Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 04 Apr 2010 02:01:53 -0700
From:      Gary Kline <kline@thought.org>
To:        glarkin@FreeBSD.org
Cc:        FreeBSD Mailing List <freebsd-questions@FreeBSD.org>
Subject:   Re: perl qstn...
Message-ID:  <1270371713.5861.98.camel@tao.thought.org>
In-Reply-To: <4BB8108A.9080104@FreeBSD.org>
References:  <20100403210610.GA4135@thought.org> <4BB8108A.9080104@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 2010-04-04 at 00:07 -0400, Greg Larkin wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Gary Kline wrote:
> > guys,
> > 
> > i'm finally trying to get my private scripts and binaries in
> > ~/bin in order.   several of my perl scripts were meant to be
> > throwaway ... but a few seem to be more useful and i would have
> > to have informational or usage{} type messages.  
> > 
> > if a .pl script has to have at least one arg, is there an easy
> > way to do that?  can i have a perl fn called usage() that would
> > be fed various strings?
> > 
> > tia,
> > 
> > gary
> > 
> > 
> > 
> 
> Hi Gary,
> 
> Check out this Perl module that builds on Getopt::Long, but also
> includes support for echoing usage messages for each option:
> http://search.cpan.org/~rjbs/Getopt-Long-Descriptive-0.085/lib/Getopt/Long/Descriptive.pm
> 
> Hope that helps,
> Greg

thanks for your url as well and the others to posted.  but it seems like
overkill since i dont need any explicit option or argument.  i just need
the script to tell me whether i have an arg or not.  following is
something i've kept in one of my junk drawers from when i was learning
to write bourne sscripts.  it uses the "$[token]" syntax that determines
whether there are Any args on the cmdline.  if not, the script prints a
message and exits. 

#!/bin/sh
if [ $# -eq 0 ]
then
        echo "No args; need filename."
else
        echo "$1"
fi

After a couple hours experimentation, the following does the same for my
perl scripts:


#!/usr/bin/perl
$argc = @ARGV;
if (! $argc ) {
        printf("No args; need filename.\n");
}
else {
        printf("%s\n", @ARGV);
}

gary





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1270371713.5861.98.camel>