Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: hash to text

by antirice (Priest)
on Aug 14, 2004 at 20:01 UTC ( [id://383008]=note: print w/replies, xml ) Need Help??


in reply to hash to text

Four things:

  1. The way to get the value you want is with ${$h{'word1'}[0]}.
  2. If you'd have employed use strict, you'd notice that %h isn't yet defined when you try to grab $h{'word1'}. The value that $h{'word2}[0] currently contains is a reference to undef.
  3. You could have confirmed all of this by using Data::Dumper with print Dumper(\%h);.
  4. Why are you assigning a reference to an arrayref?

Proper way to do this would be to do:

my %h = ( 'word1'=>[2,3], 'word2'=>[undef,3], 'word3'=>[1,2] ); $h{word2}[0] = $h{word1}; print "@{$h{word2}[0]}\n"; __END__

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-24 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found