in reply to Nicest way of getting STDIN a beauty contest
update: bah, needlessly complicated. Just use <> and check the result.
I'd do it like this:
#!/usr/bin/perl use strict; use warnings; my @hosts; while(<>){ chomp; die "usage: do_something [file]\n" if $ARGV eq '-' and ! $_; next unless $_; push @hosts, $_; } print "Read hosts:\n"; print $_,$/ for @hosts;
That will bail at an empty input line from STDIN. Works with
do_something hosts do_something < hosts echo foo | do_something do_something type type type
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Nicest way of getting STDIN a beauty contest
by mickep76 (Beadle) on Oct 09, 2009 at 09:34 UTC |