Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone see what I'm doing wrong below. I'm just trying to populate an array 'mc_mth_attrs' with an array stored in a hash:
@mc_mth_attrs = @{$mc_attr_lookup{$key}->{attrs}}; print Dumper(@mc_mth_attrs);
my error says: Can't use an undefined value as an ARRAY reference

Thanks in advance

Replies are listed 'Best First'.
Re: trying to populate an array from a hash of arrays
by Zaxo (Archbishop) on Jun 20, 2003 at 13:54 UTC

    Try print Dumper(\@mc_mth_attrs); Dumper wants a reference to the thing to dunp.

    If you still have a problem after that, you'll need to show us how %mc_attr_lookup is made.

    After Compline,
    Zaxo

Re: trying to populate an array from a hash of arrays
by halley (Prior) on Jun 20, 2003 at 13:56 UTC
    My 200th post!

    You didn't include which line has the error, or whether it was a 'warn' or 'carp', so here are both possible reasons:

    For some value of $key, the expression $mc_attr_lookup{$key}->{attrs} is undefined. Try dumping $mc_attr_lookup first to understand and validate its structure.

    The Dumper routine expects scalars, and some element in @mc_mth_attrs is undefined. You probably wanted to do print Dumper \@mc_mth_attrs; instead.

    --
    [ e d @ h a l l e y . c c ]

      Thanks for the advice....and yes it was a silly mistake. Sorry to have wasted your time with this.

      Thanks again!

Re: trying to populate an array from a hash of arrays
by adrianh (Chancellor) on Jun 20, 2003 at 13:56 UTC

    Looks like $mc_attr_lookup{$key}->{attrs} isn't an array reference.

    Listen to the code :-)

    Print it out with Data::Dumper. See what it really is.