Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!mcsun!hp4nl!star.cs.vu.nl!gpvos From: gpvos@cs.vu.nl (Gerben 'P' Vos) Newsgroups: comp.lang.perl Subject: Re: Perl STDIN and ARGV Message-ID: <8876@star.cs.vu.nl> Date: 30 Jan 91 00:21:07 GMT References: <1991Jan28.083825.15064@sgitokyo.nsg.sgi.com> Sender: news@cs.vu.nl Lines: 30 kandall@sgitokyo.nsg.sgi.com (Michael Kandall) writes: >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? Perl handles this automagically with the <> construct. while (<>) { &do_what_you_want($_); } >Can a FILEHANDLE be associated with an arbitrary array? A natural >equivalence would be one array element per line. If you mean what i think you mean, you can't. You can, however, slurp in a whole file into an array (one element per line), work on it, and then print the whole thing, along the lines of open(FILE, "foo"); @array = ; # slurp close(FILE); &dwim(@array); open(FILE, ">foo"); print @array; # not sure about the line separators, check out yourself. close(FILE);