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

Re^2: Learning about Arrays and Hashes - printing pieces of them

by Anonymous Monk
on Jan 28, 2015 at 19:56 UTC ( [id://1114808]=note: print w/replies, xml ) Need Help??


in reply to Re: Learning about Arrays and Hashes - printing pieces of them
in thread Learning about Arrays and Hashes - printing pieces of them

Hi Mom!

I see my dog forgot to point to my hound.... I was missing the > pointing to hound. Thank you!

What happens when I try:

print $rec -> [Buick], "\n";
Does that just print "Buick" or does it print a 0? I didn't find a specific example of that so I was wondering how I find the value Buick.

Could I do something like this:

my $favoriteCar = $rec->{LOOKUP}[0]; print "My favorite car is ", $favoriteCar, "\n";
Thank you!

Raye Ann

Replies are listed 'Best First'.
Re^3: Learning about Arrays and Hashes - printing pieces of them
by NetWallah (Canon) on Jan 28, 2015 at 20:10 UTC
    You can answer these questions by running the code yourself, under the perl built-in debugger.

    Just run you rprogam like this:

    perl -d <Your-program-file-name>
    Inside the debugger prompt , use the "h" (help) command , using "x" check the values of the variables.

    Note: You need to FIRST use the "s" command to get the $rec variable initialized.

    Here are the results of running your program - it includes answers to your questions:

    DB<1> s main::(junk.pl:10): print $rec->{TEXT},"\n", main::(junk.pl:11): $rec->{SEQUENCE}[0],"\n", main::(junk.pl:12): $rec->{LOOKUP}{"dog"},"\n"; DB<1> x $rec -> [Buick] Not an ARRAY reference at (eval 7)[/usr/lib/perl5/5.10.0/perl5db.pl:63 +8] line 2. DB<2> x $rec -> {LOOKUP} -> {cars} 0 'Buick' DB<3> x $rec -> {LOOKUP} [0] Not an ARRAY reference at (eval 9)[/usr/lib/perl5/5.10.0/perl5db.pl:63 +8] line 2. DB<4> x $rec -> {LOOKUP} {dog} 0 'hound' DB<5> q

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-04-23 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found