Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^3: Hash of Array references

by choroba (Bishop)
on Aug 04, 2014 at 15:08 UTC ( #1096148=note: print w/replies, xml ) Need Help??

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

See perlreftut - Mark's very short tutorial about references for details.
print "Number entered is : $input\n"; print "User for the number $input is: $users{$input}[0]\n"; print "Comments for the number $input is: $users{input}[1]\n";
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^4: Hash of Array references
by sravs448 (Acolyte) on Aug 04, 2014 at 15:24 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"; }
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096148]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-05-20 21:39 GMT
Find Nodes?
    Voting Booth?