in reply to Passing parameters to Perl Script

If you give your input to the script in a via pipe, it will be acessible on standard input, not in the argument list.

# your above script will work with this invocation: perlscript one two

Alternatively Use the -n switch to perl itself, which causes your code to run in a loop with $_ set to a line of input every iteration (see perlrun for more details):

#!/usr/bin/perl -n use strict; use warnings; my @words = split; # "split /\s+/, $_", more or less print "passed $_\n" for @words;

Update: Added missing my keyword, thanks K_M_McMahon.

Replies are listed 'Best First'.
Re^2: Passing parameters to Perl Script
by holli (Abbot) on Feb 18, 2005 at 09:13 UTC
    If that is to be run under Windows, you will need to
    - wrap your script into a batch-file using perl2bat
    c:\> pl2bat scriptname c:\> echo 1 2 3|scripname.bat
    - or pipe to perl.exe
    echo 1 2 3|perl.exe scriptname
    because of some limitations of the Windows-shell


    holli, /regexed monk/
      If that is to be run under Windows, you will need to - wrap your script into a batch-file using perl2bat
      Does it really work? I'm not saying it doesn't, I just have a doubt. More specifically I've been using pl2bat and much to my surprise and disappointment I've noticed that I cannot use redirection of output (I had to add '-o' cmd line switches to "utilities" only moderately more complex than one-liners!). Don't know about input...

      I would check by myself but I'm under Linux now and I won't have access to a Windoze machine up until this evening...