&foo(); # the same
&foo; # foo() get current args, like foo(@_) !!
- foo; # like foo() IFF sub foo predeclared, else "foo"
+ use strict 'subs';
+ foo; # like foo() iff sub foo predeclared, else
+ # a compile-time error
+ no strict 'subs';
+ foo; # like foo() iff sub foo predeclared, else
+ # a literal string "foo"
Not only does the C<&> form make the argument list optional, it also
disables any prototype checking on arguments you do provide. This
The array has 6 elements: 0, 1, 2, undef, undef, 5
The behavior of local() on non-existent members of composite
-types is subject to change in future.
+types is subject to change in future. The behavior of local()
+on array elements specified using negative indexes is particularly
+surprising, and is very likely to change.
=head3 Localized deletion of elements of composite types
X<delete> X<local, composite type element> X<local, array element> X<local, hash element>
sub myjoin ($@) myjoin ":", $a, $b, $c
sub mypop (\@) mypop @array
sub mysplice (\@$$@) mysplice @array, 0, 2, @pushme
- sub mykeys (\[%@]) mykeys %{$hashref}
+ sub mykeys (\[%@]) mykeys $hashref->%*
sub myopen (*;$) myopen HANDLE, $name
sub mypipe (**) mypipe READHANDLE, WRITEHANDLE
sub mygrep (&@) mygrep { /foo/ } $a, $b, $c
is either a constant or a lexically-scoped scalar which has no other
references, then it will be used in place of function calls made
without C<&>. Calls made using C<&> are never inlined. (See
-F<constant.pm> for an easy way to declare most constants.)
+L<constant> for an easy way to declare most constants.)
The following functions would all be inlined:
C<system> with those arguments. All you'd do is:
sub AUTOLOAD {
- my $program = $AUTOLOAD;
- $program =~ s/.*:://;
- system($program, @_);
+ our $AUTOLOAD; # keep 'use strict' happy
+ my $program = $AUTOLOAD;
+ $program =~ s/.*:://;
+ system($program, @_);
}
date();
- who('am', 'i');
+ who();
ls('-l');
In fact, if you predeclare functions you want to call that way, you don't
use subs qw(date who ls);
date;
- who "am", "i";
+ who;
ls '-l';
A more complete example of this is the Shell module on CPAN, which