take the file name in as an argument of the function

2002-01-16 Thread Booher Timothy B 1stLt AFRL/MNAC

Hello all.

I want to be able to take the file name in as an argument of the function,
for example:

%Extract.pl MyFile.txt

I know that I could use:

#!/usr/bin/perl
while () {

}

But how could I take two arguments from the command line:

i.e. my guess:

%Test.pl Foo Bar

#/!/usr/bin/perl
 $A = $ARGV[0];
 $B = $ARGV[1];
print Thing A: $A  Thing B: $B;

Thanks,

Tim



Re: take the file name in as an argument of the function

2002-01-16 Thread Johnathan Kupferer



But how could I take two arguments from the command line:

i.e. my guess:

%Test.pl Foo Bar

#/!/usr/bin/perl
 $A = $ARGV[0];
 $B = $ARGV[1];
   print Thing A: $A  Thing B: $B;


I think you already answered your own question!  Though your shebang 
line should be #!/usr/bin/perl.

Other ways of doing this are:

#!/usr/bin/perl
($A, $B) = @ARGV;

#!/usr/bin/perl
use strict;
# Lets be strict and explicitly declare $A and $B.
my ($A, $B) = @ARGV;

#!/usr/bin/perl
use strict;
# After this @ARGV will be two elements shorter.
# if @ARGV contains ('foo.txt','bar.txt','another.txt','yetanother.txt') now
my $A = shift @ARGV;
my $B = shift @ARGV;
# then @ARGV contains ('another.txt','yetanother.txt') now.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: take the file name in as an argument of the function

2002-01-16 Thread Jonathan E. Paton

Hi,

For anything more complex than a simple script you should
consider using switches and parameters.

You know, something like this [highly dangerous] dd
command:

dd if=/dev/zero of=/dev/hda7 count=1 bs=512

Or:

tar -zxvf archive.tar.gz

Processing these can be quite hard, but guess what... there
is a module to do it for you.  Take a look at the
documentation for them at:

perldoc Getopt::Long
perldoc GetOptions
perldoc GetOptions::Std

To do that dd command you'd do _something_ like:

use GetOptions;

my ($if, $of, $bs, $count);
GetOptions(if:s= \$if,
   of:s= \$of,
   bs:s= \$bs,
   count:s = \$count);

My preference is for Getopt::Long, but didn't fit my
example.  Hope you find this useful knowledge, whether or
not it fits in with your current task.

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]