http://www.perlmonks.org?node_id=515098

Dear monks,

One interesting way to live up to the principle of least surprise is to shock your users so frequently and so thoroughly that soon nothing will surprise them anymore. I'm there.

Watch:

% perl -Mstrict -le 'my $x; my @y = @$x; print "=> ", ref $x' Can't use an undefined value as an ARRAY reference at -e line 1. % perl -Mstrict -le 'my $x; sub {}->( @$x ); my @y = @$x; print "=> ", + ref $x' => ARRAY

The useless subroutine call sub {}->( @$x ) autovivifies @$x. Incidentally, builtin functions do not provide a similar service:

% perl -Mstrict -le 'my $x; scalar( @$x ); my @y = @$x; print "=> ", r +ef $x' Can't use an undefined value as an ARRAY reference at -e line 1.

Bug? Feature? You decide.

I'm sure that more erudite monks will be able to scrape up the documentation for this bugeature from some recondite corner of the Perl docs, but an innocent grep for "autoviv" in perlsub left me none the wiser.

Cheers.

Update: Fixed the ill-chosen example of qw(...) as "builtin function". Thanks to japhy for pointing out the gaffe.

the lowliest monk