Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: References with hashes

by chargrill (Parson)
on Feb 15, 2007 at 04:50 UTC ( #600133=note: print w/ replies, xml ) Need Help??


in reply to References with hashes

This simple change gets your program closer to working:

#!/usr/bin/perl use strict; use warnings; my %address; $address{Bray} = { Name => 'Braden Mailloux', Str => 'kapellenstr. 1', EMail => 'brayshakes@gmail.com' }; my $email = $address{Bray}->{EMail}; print_address($address{Bray});

After this change, running it only gives the error "Undefined subroutine &main::print_address called at bray.pl line 17."

You could also do this:

#!/usr/bin/perl use strict; use warnings; my %address = ( Bray => { Name => 'Braden Mailloux', Str => 'kapellenstr. 1', EMail => 'brayshakes@gmail.com' }); my $email = $address{Bray}->{EMail}; print_address($address{Bray});

I believe it has something to do with the hash key not existing as you're trying to declare it lexically, but I couldn't find anything concrete (to me) in the docs. See my and perlsub for more details.



--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)


Comment on Re: References with hashes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2014-12-18 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (62 votes), past polls