in reply to Re: Array reference error
in thread Array reference error

There doesn't seem to be an  'undefined' warning (see perllexwarn), but turning off strict references together with  'uninitialized' warnings (both of these actions taken within the narrowest possible scope, of course) seems to do the trick.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my %res; ;; no strict qw(refs); no warnings qw(uninitialized); ;; @{$res{'act'}} = sort { return 0 unless $a->{'act'} =~ /^move/ and $b->{'act'} =~ /^move/; return $a->{'act'} cmp $b->{'act'}; } @{$res{'acts'}}; dd \%res; " { act => [] }

Replies are listed 'Best First'.
Re^3: Array reference error
by tobyink (Canon) on Feb 27, 2014 at 22:39 UTC

    Oops, yes. I meant uninitialized. Fixed.

    Turning off strict refs should not be necessary for this.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

      For this particular example,  no strict 'refs'; seems to be essential. (Checked under both ActiveState 5.8.9 and Strawberry 5.14.4.1)

      c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my %res; ;; no warnings qw(uninitialized); ;; @{$res{'act'}} = sort { return 0 unless $a->{'act'} =~ /^move/ and $b->{'act'} =~ /^move/; return $a->{'act'} cmp $b->{'act'}; } @{$res{'acts'}}; dd \%res; " Can't use an undefined value as an ARRAY reference at -e line 1.