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?
        $data->[0]{data} and $$data[0]{data} are equivalent. And so is $data->[0]->{data}. Use whatever you prefer.

        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