Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: uninitialized string variable

by suhailck (Friar)
on Aug 13, 2010 at 17:57 UTC ( [id://854961]=note: print w/replies, xml ) Need Help??


in reply to Re^3: uninitialized string variable
in thread uninitialized string variable

If $data is a reference to an AoH, then the following is sufficient
perl -le '$data=[{ data => 1 },{a => 2, b => 3}];print $$data[0]->{dat +a}' 1
And if you try the below code, you can see the error u got,
perl -wle '$data=[{ data => 1 },{a => 2, b => 3}];print $$data[1]->{c +}' Use of uninitialized value in print at -e line 1.
see perldsc for details.

Replies are listed 'Best First'.
Re^5: uninitialized string variable
by JavaFan (Canon) on Aug 13, 2010 at 18:17 UTC
    $ perl -wE '$data = [{"data" => "foo"}]; say @$data[0]->{"data"}' foo
    However, I would write that as
    $$data[0]{"data"}
    which doesn't use an unneeded arrow, and uses the more usual dereference sigil. (I guess this case isn't caught by "Scalar value @... is better written as $...).
      Isn't it the same as $data->[0]{data} I'd use?

        From what I have tried it is the same thing (if you put "data") That does look cleaner. I was just doing it the way I learned how to. I like the cleaned up look though. Thanks

        $data->[0]{data} and $$data[0]{data} are equivalent. And so is $data->[0]->{data}. Use whatever you prefer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-25 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found