From owner-freebsd-questions@FreeBSD.ORG Sun Apr 4 09:01:58 2010 Return-Path: Delivered-To: freebsd-questions@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 30448106566C for ; Sun, 4 Apr 2010 09:01:58 +0000 (UTC) (envelope-from kline@thought.org) Received: from ethic.thought.org (plato.thought.org [209.180.213.209]) by mx1.freebsd.org (Postfix) with ESMTP id E20638FC0A for ; Sun, 4 Apr 2010 09:01:57 +0000 (UTC) Received: from [10.47.0.250] (tao.thought.org [10.47.0.250]) (authenticated bits=0) by ethic.thought.org (8.14.3/8.14.3) with ESMTP id o3491rEs076276; Sun, 4 Apr 2010 02:01:54 -0700 (PDT) (envelope-from kline@thought.org) From: Gary Kline To: glarkin@FreeBSD.org In-Reply-To: <4BB8108A.9080104@FreeBSD.org> References: <20100403210610.GA4135@thought.org> <4BB8108A.9080104@FreeBSD.org> Content-Type: text/plain; charset="UTF-8" Organization: Thought Unlimited Date: Sun, 04 Apr 2010 02:01:53 -0700 Message-ID: <1270371713.5861.98.camel@tao.thought.org> Mime-Version: 1.0 X-Mailer: Evolution 2.28.2 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=3.6 tests=ALL_TRUSTED,BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.0 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on ethic.thought.org Cc: FreeBSD Mailing List Subject: Re: perl qstn... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: kline@thought.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Apr 2010 09:01:58 -0000 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