1nickt has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, in perlrun under the documentation for the -a switch it states:

-a implicitly sets -n.

My testing seems to show this is not the case:

$ cat test.dat foo bar baz quux $ perl -wMstrict -M5.010 -ane 'say $F[0]' test.dat foo baz $ perl -wMstrict -M5.010 -ae 'say $F[0]' test.dat Variable "@F" is not imported at -e line 1. Global symbol "@F" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

Am I missing something?

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: perlrun: -a implicitly sets -n
by stevieb (Canon) on Jul 30, 2015 at 23:21 UTC

    Update: I just looked, and the first version I can find that this was introduced is in v5.20.0, here, so you probably are on v5.18.0 or earlier.

    Which version of perl, and in which version of perlrun did you glean that from? I'm on v5.22.0.

    steve@spek ~/scratch $ perl -wMstrict -M5.010 -ae 'say $F[0]' test.dat foo baz

      Thanks stevieb and browseruk, indeed, I am on 5.16.0, and the perlrun I consulted was the on-line version. I'll submit a patch with a note.

      The way forward always starts with a minimal test.

        Hey 1nickt, the online version (by default) is v5.22.0. The v5.16.0 version doesn't have that info, so I don't know if a patch is necessary.

        Can you post a link to the version of perlrun you found this in, just to be sure?

Re: perlrun: -a implicitly sets -n
by BrowserUk (Patriarch) on Jul 30, 2015 at 23:27 UTC

    It seems that feature was added somewhere between versions 5.18 & 5.20:

    C:\test>\perl5.18\perl\bin\perl.exe -mstrict -waE"say @F" counts C:\test>\perl5.18\perl\bin\perl.exe -mstrict -wanE"say @F" counts 00000018801880 C:\test>\Perl5.20\bin\perl.exe -mstrict -wanE"say @F" counts 00000018801880 C:\test>\Perl5.20\bin\perl.exe -mstrict -waE"say @F" counts 00000018801880

    Anyone got any experience of this phone's predecessor?

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

      Yep, I did some research (and updated my first post). It became effective during 5.19 (officially available in 5.20).