Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!helios!bcm!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Perl STDIN and ARGV Message-ID: <1991Jan28.194851.9307@convex.com> Date: 28 Jan 91 19:48:51 GMT References: <1991Jan28.083825.15064@sgitokyo.nsg.sgi.com> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 28 Nntp-Posting-Host: pixel.convex.com From the keyboard of kandall@sgitokyo.nsg.sgi.com (Michael Kandall): :A common UNIX(tm) System utility usage is to process command line args, :and if they are not present to process stdin. : :What's the standard paradigm for switching between these two in Perl? Normally you do something like this: while (<>) { # <> is magic # blah } This will read from the files on the command line, or stdin if none are given, and will correctly interpret "-" as stdin in the midst of the stream. If you want to process leading -foo options, you can use one of the getopts libraries: require 'getopts.pl'; &Getopts('wxyza:b:') || &usage; You mIhgt also use even the -s flag for simple things. For really sophisticated argument parsing, you might wish to roll your own. --tom -- "Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now he can finally have the whole O/S built-in to his editor like he always wanted!" --me (Tom Christiansen )