Perl script to Create a hash as capitals of any 5 states of india and print the capital if state is entered &

0 votes
asked Jul 24 by Atluri Nikhitha (130 points)
edited Jul 25 by Atluri Nikhitha
Create a hash as capitals of any 5 states of india and print the capital if state is entered & print a state if capital is entered in perl

1 Answer

0 votes
answered Jul 26 by xDELLx (1,450 points)
%state_capitals= ('AA', 'aa', 'BB','bb','CC','cc','DD','dd','EE','ee');

@states = keys %state_capitals;
@capitals = values %state_capitals;
$size = @states;
%capitals_state= ();

for ($x=0;$x<$size;$x=$x+1){
        #print "$x\n";
        #print "$states[$x] \t  $capitals[$x]\n";
        $capitals_state{@capitals[$x] } = @states[$x];

}

print "$state_capitals{'AA'}\n";
print "$capitals_state{'aa'}\n";
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...