monkfan has asked for the wisdom of the Perl Monks concerning the following question:
or from STDIN$ perl othercode.pl | perl thiscode.pl
Currently I have this construct. But is there a better way to do it?$ perl thiscode.pl SOMEFILE.txt
#!/usr/bin/perl -w use strict; # thiscode.pl my $file = $ARGV[0]; my @lines; if($file) {@lines = `cat $file`;} else {@lines = <STDIN>;} # Update: Also, can I do better than 'slurping' +here? foreach (@lines) { #Do my stuff here }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to accept ARG from PIPE or STDIN?
by moot (Chaplain) on Mar 17, 2005 at 01:05 UTC | |
|
Re: How to accept ARG from PIPE or STDIN?
by perlfan (Parson) on Mar 17, 2005 at 02:17 UTC | |
by ikegami (Patriarch) on Mar 17, 2005 at 03:02 UTC | |
by monkfan (Curate) on Mar 17, 2005 at 03:16 UTC | |
by ikegami (Patriarch) on Mar 17, 2005 at 04:34 UTC | |
|
Re: How to accept ARG from PIPE or STDIN?
by Fletch (Bishop) on Mar 17, 2005 at 04:14 UTC |