in reply to Re: Hash of Array references
in thread Hash of Array references

It worked great. But how can I access the respective $user and $comments independetly?

print 'Select a number: '; my $input = <STDIN>; chomp $input; if (exists $users{$input}) { print "Number entered is : $users{$input} \n"; print "User for the number $users{$input} is : \n"; print "Comments for the number $users{input} is : \n"; } else { print "Unknown number.\n"; }

Something like this in the output

Number entered is : 12345678 User for number 123456789 is : Sam Comments for the number 123456789 is : Changed "abc" in the file

Replies are listed 'Best First'.
Re^3: Hash of Array references
by choroba (Cardinal) on Aug 04, 2014 at 15:08 UTC

      Thanks a lot..I just got it.. But is there any way to store the number as well in the array?. I need to provide user with 2 options.Either display all the details or display details of any specific number

      print "PRESS 1 to display a single number details \n 2 to display all the numbers and details\n or any other key to EXIT :"; chomp($option2=<STDIN>); if ($option2 =="1") { print "Enter the number:"; my $input = <STDIN>; chomp $input; if (exists $users{$input}) { print "@{ $users{$input} }\n"; print "$users{$input}[0] \n"; print "$users{$input}[1] \n"; } else { print "Unknown number.\n"; } } elsif ($option2 == "2") { # display all the numbers and their respective user and co +mments.something like the below one # The details for number 1234567 are user : sam, comments: +changed abc in a file. The details for number 343434 are user:john, comments: d +eleted abc in a file } else { print "Invalid option\n"; }
        Do you need the number in the same order as in the input? If not, you can just
        for my $num (keys %users) { print "The details for number $num are user:$users{$num}[0], comme +nts: $users{$num}[1]\n"; }
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ