From owner-freebsd-questions@FreeBSD.ORG Thu Apr 27 22:18:25 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 7F35E16A402 for ; Thu, 27 Apr 2006 22:18:25 +0000 (UTC) (envelope-from arnsholt@broadpark.no) Received: from mail42.e.nsc.no (mail42.e.nsc.no [193.213.115.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id EAEE643D45 for ; Thu, 27 Apr 2006 22:18:24 +0000 (GMT) (envelope-from arnsholt@broadpark.no) Received: from bursar.lan (ti211310a080-16232.bb.online.no [85.166.63.104]) by mail42.nsc.no (8.13.6/8.13.5) with ESMTP id k3RMIMmb028152 for ; Fri, 28 Apr 2006 00:18:23 +0200 (CEST) From: Arne Skjaerholt To: freebsd-questions@freebsd.org In-Reply-To: <20060427214854.GA2601@thought.org> References: <20060427024158.GA71123@thought.org> <20060427031043.GA69851@gothmog.pc> <20060427214854.GA2601@thought.org> Content-Type: text/plain Date: Fri, 28 Apr 2006 03:35:03 +0200 Message-Id: <1146188104.7085.8.camel@bursar> Mime-Version: 1.0 X-Mailer: Evolution 2.4.2.1 Content-Transfer-Encoding: 7bit Subject: Re: scripting languages... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: arnsholt@broadpark.no List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Apr 2006 22:18:25 -0000 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. Your neighbourhood Perl afficionado, Arne :wq