Getting fields into perl script

H

Hugh Kang

In Unix script, I use $1 and $2 to get the fields.
For example, when I do,
./start_test start 10

In start_test script, I check
case $1 in
'start')

.....
TIME=$2
.....
;;
esac

How do I do the same thing with a perl script?

Many thnaks in advance
Hugh
 
A

Anno Siegel

Hugh Kang said:
In Unix script, I use $1 and $2 to get the fields.
For example, when I do,

In start_test script, I check
case $1 in
'start')

.....
TIME=$2
.....
;;
esac

How do I do the same thing with a perl script?

Well, Perl doesn't have a case statement, so there isn't a direct
equivalent. (See "perldoc -q case", however.)

This does about the same (untested):

#!/usr/bin/perl
use strict; use warnings;

my $time;
$time = $ARGV[ 2] if $ARGV[ 1] eq 'start';

Anno
 
J

Jens M. Felderhoff

In Unix script, I use $1 and $2 to get the fields.
For example, when I do,

In start_test script, I check
case $1 in
'start')

.....
TIME=$2
.....
;;
esac

How do I do the same thing with a perl script?

SWITCH: {
...
$ARGV[0] eq 'start' && do {
...
$time = $ARGV[1];
...
last SWITCH;
};
...
}

But, never forget, TMTOWTDI ;)

Cheers

Jens
 
T

Tad McClellan

Hugh Kang said:
In Unix script, I use $1 and $2 to get the fields.


You access command line arguments in Perl via the @ARGV array.

print "$_\n" for @ARGV; # echo all command line arguments
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top