Permalink
Browse files

Be more explicit about how to work with $AUTOLOAD

Update code sample to account for 'use strict', avoiding:

    Global symbol "$AUTOLOAD" requires explicit package name

Committer: Improve example so as to:

Use our now-standard 4-space indents in code samples; correct call to
'who' so that it produces same output on Linux and FreeBSD.
  • Loading branch information...
KES777 authored and jkeenan committed Sep 13, 2018
1 parent c0f2b63 commit 3366620504dab0181dd870c9ff65aaad992d8899
Showing with 6 additions and 5 deletions.
  1. +6 −5 pod/perlsub.pod
View
@@ -1947,20 +1947,21 @@ let's pretend that a function that wasn't defined should just invoke
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
even need parentheses:
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

0 comments on commit 3366620

Please sign in to comment.