sleet has asked for the wisdom of the Perl Monks concerning the following question:
But recently I noticed for a long-running process it wasn't doing any work until the data was all collected, so I modified the code to process data from STDIN as it's received:my @ids = do { @ARGV || -t STDIN ? @ARGV : <STDIN> }; chomp @ids;
Is there a better idiom to handle this?my $fh; if (@ARGV || -t STDIN) { open $fh, '<', \ join("\n", @ARGV); } else { $fh = *STDIN } while (defined(my $id = <$fh>)) { chomp $id; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting data from either ARGV or STDIN
by LanX (Saint) on Mar 11, 2021 at 23:03 UTC | |
by sleet (Pilgrim) on Mar 11, 2021 at 23:26 UTC | |
by LanX (Saint) on Mar 11, 2021 at 23:43 UTC | |
by LanX (Saint) on Mar 11, 2021 at 23:30 UTC |