in reply to How to keys($array_ref)?

When you test the syntax of a perl expression, start off with simple cases:

$ perl -wE 'say keys [1, 2]' 01 $ perl -wE 'say keys { a => 1, b => 2 }' ab

So, works fine. Something seems to be off in your code, reducing it to a few essential lines probably shows the problem more clearly.

It also generally helps if you're more specific than "doesn't seem to work" -- do you get an error message, or some wrong result? What do you expect, what do you get?

Update: I removed some irrelevant parts from your code, and got an empty line, which makes sense since you haven't posted any code that initializes %chassis. When I add some initialization, it works as expected:

$returns{'do_stuff'} = do_stuff(); print keys($returns{'do_stuff'}->[2] ) , "\n"; sub do_stuff { my %chassis = ( a => 1, b => 2 ); my @returns = (0 , "Success" , \%chassis); return(\@returns); } __END__ ab

(Tested with perl 5.14.1).

Replies are listed 'Best First'.
Re^2: How to keys($array_ref)?
by networker2149 (Novice) on Sep 17, 2011 at 02:36 UTC

    Figured it out. I was accidentally creating a second reference in the return array with

    my @returns = ["blah","blah","blah"]; return(\@returns);
    which should have been:
    my @returns = ("blah","blah","blah"); return(\@returns);
    so I ended up with a reference to a reference to the array I was trying to access instead of a reference to the data.