in reply to Not an ARRAY reference, even though it is?
Do you have use warnings; at the top of your program? It appears not, as this code:
produces this output for me:[nick:~/monks]$ perl -Mstrict -Mwarnings -e" my @foo; push @foo = {bar=>'baz'}; "
As you can see the first line of the output is more descriptive about the error, which often helps you find it more quickly. So always use warnings;.Useless use of push with no values at -e line 2. push on reference is experimental at -e line 2. Not an ARRAY reference at -e line 2.
As an aside: You don't show what you do with your array, but I am wondering if it might not be more useful for you to have your invoices stored in a hash so you can retrieve them by index:
#! perl use strict; use warnings; my $cast = list_characters()->{'cast'}; print "The Human is $cast->{'Human'}->{'fname'} $cast->{'Human'}->{'ln +ame'}."; print " He is always displaying $cast->{'Human'}->{'characteristic'}.\ +n"; sub list_characters { my $Guide; $Guide->{'cast'}->{'Human'} = { fname => 'Arthur', lname => 'Dent', characteristic => 'bewilderment', }; $Guide->{'cast'}->{'Betelgeusian'} = { fname => 'Zaphod', lname => 'Beeblebrox', characteristic => 'narcissism', }; $Guide->{'cast'}->{'Robot'} = { fname => 'Marvin', lname => 'the Paranoid Android', characteristic => 'depression', }; return $Guide; } __END__
Output:
[09:07][nick:~/monks]$ perl 1139851.pl The Human is Arthur Dent. He is always displaying bewilderment.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Not an ARRAY reference, even though it is?
by ultranerds (Hermit) on Aug 25, 2015 at 17:09 UTC |