From owner-freebsd-questions@FreeBSD.ORG Thu Apr 27 23:58:42 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A660816A40A for ; Thu, 27 Apr 2006 23:58:42 +0000 (UTC) (envelope-from kline@tao.thought.org) Received: from tao.thought.org (dsl231-043-140.sea1.dsl.speakeasy.net [216.231.43.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5D97143D46 for ; Thu, 27 Apr 2006 23:58:40 +0000 (GMT) (envelope-from kline@tao.thought.org) Received: from tao.thought.org (localhost [127.0.0.1]) by tao.thought.org (8.13.4/8.13.1) with ESMTP id k3RNwT3l003439; Thu, 27 Apr 2006 16:58:30 -0700 (PDT) (envelope-from kline@tao.thought.org) Received: (from kline@localhost) by tao.thought.org (8.13.4/8.13.1/Submit) id k3RNwSpA003438; Thu, 27 Apr 2006 16:58:28 -0700 (PDT) (envelope-from kline) Date: Thu, 27 Apr 2006 16:58:28 -0700 From: Gary Kline To: Arne Skjaerholt Message-ID: <20060427235828.GD2601@thought.org> References: <20060427024158.GA71123@thought.org> <20060427031043.GA69851@gothmog.pc> <20060427214854.GA2601@thought.org> <1146188104.7085.8.camel@bursar> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1146188104.7085.8.camel@bursar> User-Agent: Mutt/1.4.2.1i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: Observing 19++ years of service to the Unix community Cc: freebsd-questions@freebsd.org Subject: Re: scripting languages... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Apr 2006 23:58:42 -0000 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@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" -- Gary Kline kline@thought.org www.thought.org Public service Unix