SPUG: running script with the variables on the same line

Medrano-Zaldivar, L E LMedrano-Zaldivar at ciber.com
Mon May 30 09:37:18 PDT 2005


I really appreciate all your mails and actually I found code example of what I was looking for:
 
  

#!/usr/bin/perl
print "My name is $0 \n";
print "First arg is: $ARGV[0] \n";
print "Second arg is: $ARGV[1] \n";
print "Third arg is: $ARGV[2] \n";
$num = $#ARGV + 1; print "How many args? $num \n";
print "The full argument string was: @ARGV \n";

Now if you run this script, here's what you'll see:

$ ./testvars dogs can whistle
My name is testvars.pl
First arg is: dogs
Second arg is: can
Third arg is: whistle
How many args? 3
The full argument string was: dogs can whistle

Thanks,
Luis

 
________________________________

From: spug-list-bounces at pm.org on behalf of Tim Maher
Sent: Mon 5/30/2005 10:07 AM
To: John W. Krahn
Cc: SPUG
Subject: Re: SPUG: running script with the variables on the same line



On Sun, May 29, 2005 at 08:31:00PM -0700, John W. Krahn wrote:
> Tim Maher wrote:
> > On Sun, May 29, 2005 at 07:31:04PM -0700, Jay Scherrer wrote:
> >
> >>I was thinking of $argv, but is that only used for files?
> >>Jay Scherrer
> >
> > Yes; That variable provides the name of the currently open file
> > when you use -n/-p to get an "implicit input-reading loop".
>
> Perl is case sensitive so the variable you are looking for is $ARGV.
> perldoc perlvar

Quite right; and it's interesting how my perceptual systems did
automatic error-correction on that! 8-}

-Tim
*--------------------------------------------------------------------------*
| 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"   |
|  See http://manning.com/Maher for details, and email notification signup |
*--------------------------------------------------------------------------*
_____________________________________________________________
Seattle Perl Users Group Mailing List 
     POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
    MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
    WEB PAGE: http://seattleperl.org/




More information about the spug-list mailing list