This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Be more explicit about how to work with $AUTOLOAD
authorEugen Konkov <kes-kes@yandex.ru>
Thu, 13 Sep 2018 16:13:24 +0000 (19:13 +0300)
committerJames E Keenan <jkeenan@cpan.org>
Thu, 11 Oct 2018 13:19:50 +0000 (09:19 -0400)
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.

pod/perlsub.pod

index a761e3d..cea60a5 100644 (file)
@@ -1947,12 +1947,13 @@ 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
@@ -1960,7 +1961,7 @@ 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