
no autovivication for subs
Charles DeRykus wrote in comp.lang.perl.misc:
Quote:
} >...
} >}
} >} % perl -wle ' sub f:lvalue {$_} print f() -> [0] '
} >} Can't use an undefined value as an ARRAY reference at -e line 1.
} >
} >Hm, this looks like a bug. As $_ is undefined, it should spring into
} >existence, as documented in perlref. Can you report it via perlbug?
}
} I thought autovivifying worked only for a hash or array element...
} as in perlref's example:
}
} $array[$x]->{"foo"}->[0] = "January";
}
} That is, I don't see any doc instances in this context of an
} unsubscripted lvalue which could autovivify - unless there's
} an actual array or hash ref. The base lvalue ref to the left
} of the -> as in $array->{foo}->{"foo"} will generate an error
} unless $array is a valid ref.
The following works :
<1>
Obviously $x becomes an array ref here. So why should this not
work for lvalue subs ?
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/