SPUG: running script with the variables on the same line

Tim Maher tim at consultix-inc.com
Sun May 29 18:03:25 PDT 2005

On Sun, May 29, 2005 at 06:51:34PM -0600, Medrano-Zaldivar, L E wrote:
> List,
> I have a quetion how can I set a script to grap the variables values
> on the same line where I'm running the script. For example:
> perl script.pl variable1 variable2
> What I mean with this is the script can grap this values. I hope I examplain.
> Luis

What you're looking for is the "switch" option, -s, and this syntax:
perl -s script.pl -variable1=value1 -variable2=value2

This invocation will set $variable1 in the program to value1, etc.

If you've got odd stuff in the values, then you'll probably
need to add quotes like so:

perl -s script.pl -variable1="value1" -variable2="value2"

WARNING: I've never tried this on Windoze, so there might be complications
I don't foresee there.

"perldoc perlrun" provides the documentation for this feature.

| Tim Maher, PhD     (206) 781-UNIX      (866) DOC-PERL     (866) DOC-UNIX |
| tim(AT)Consultix-Inc.Com  http://TeachMePerl.Com  http://TeachMeUnix.Com |
|   Watch for my Summer, 2005 book: "Minimal Perl for UNIX/Linux People"   |

More information about the spug-list mailing list