Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Hash of Array references

by choroba (Abbot)
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";
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^3: Hash of Array references
Download Code
Reaped: Re^4: Hash of Array references
by NodeReaper (Curate) on Aug 04, 2014 at 15:10 UTC
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096148]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-12-29 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls