scripting languages...
Gary Kline
kline at tao.thought.org
Thu Apr 27 23:58:42 UTC 2006
On Fri, Apr 28, 2006 at 03:35:03AM +0200, Arne Skjaerholt wrote:
> On Thu, 2006-04-27 at 14:48 -0700, Gary Kline wrote:
> > I like the C "main(int argc, char *argv[])" intro or
> > starting-point. main() has to be there in C. Given argc
> > and argv, I can hack away freely. /bin/sh, /bin/csh,
> > and perl's lack if arg[cv] means that I have to think about
> > how-to grab the arguments to a binary. Script ot ./a.out.
> Getting at argv/argc is actually pretty simple in Perl. The global array
> @ARGV contains the arguments given on the command-line, but not the name
> of the file (this datum is contained in $0). Therefore your argv[1] in C
> is $ARGV[0] in Perl. The number of command-line arguments can be
> obtained in two ways, either you interpret the array in a scalar context
> and get its length: ``my $argc = scalar @ARGV'' or you use the last
> index of the array and add one: ``my $argc = $#ARGV + 1''. Of course, in
> most cases you'll just want to loop over the command-line args, so a
> foreach loop should suffice, or of course one of the Getopt (Getopt::Std
> or Getopt::Long in most cases) modules.
>
So, could I say:
my $argc = $#ARGV+1; $count = 0;
while ($argc--)
{
if (! (checkErr($ARGV[$count], $count)))
{
printf("Processing %s\n", $ARGV[$count]);
doWhatever($ARGV[$count]);
}
$count++;
}
or something close-to!? If Larry Wall had only made perl
a bit closer to C, I probably would've used it more.
anyway, thanks!
gary
> Your neighbourhood Perl afficionado,
> Arne
> :wq
>
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
--
Gary Kline kline at thought.org www.thought.org Public service Unix
More information about the freebsd-questions
mailing list