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

perl -s

From:
H.Merijn Brand
Date:
May 31, 2002 03:50
Subject:
perl -s
Message ID:
20020531124543.253D.H.M.BRAND@hccnet.nl
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
           -xyz=abc.

               #!/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
1
l1:/tmp 114 > perl -sle 'print $/' -- -/ < /dev/null


l1:/tmp 115 >

-- 
H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
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: smokers@perl.org
http://archives.develooper.com/daily-build@perl.org/   perl-qa@perl.org
send smoke reports to: smokers-reports@perl.org, QA: http://qa.perl.org





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About