develooper Front page | perl.perl5.porters | Postings from May 2002

perl -s

H.Merijn Brand
May 31, 2002 03:50
perl -s
Message ID:
From perlrun:

      -s   enables rudimentary switch parsing for switches on the command
           line after the program name but before any filename arguments (or
           before an argument of --).  This means you can have switches with
           two leading dashes (--help).  Any switch found there is removed
           from @ARGV and sets the corresponding variable in the Perl
           program.  The following program prints "1" if the program is
           invoked with a -xyz switch, and "abc" if it is invoked with

               #!/usr/bin/perl -s
               if ($xyz) { print "$xyz\n" }

           Do note that --help creates the variable ${-help}, which is not
           compliant with "strict refs".

The docs do not state that -/ does not work which would otherwise be a nice
shortcut to -e 'BEGIN{$/=1}'

l1:/tmp 113 > perl -sle 'print $xyz' -- -xyz < /dev/null
l1:/tmp 114 > perl -sle 'print $/' -- -/ < /dev/null

l1:/tmp 115 >

H.Merijn Brand        Amsterdam Perl Mongers (
using perl-5.6.1, 5.8.0 & 631 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
  WinNT 4, Win2K pro & WinCE 2.11.  Smoking perl CORE:
send smoke reports to:, QA: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About