in reply to Getting data from either ARGV or STDIN
Just, according to -X is -t defaulting to STDIN. So you could spare a word.
2 other alternatives come to mind ...
An alternative approach which seems cleaner to me could be to create an iterator which either implements:
sub iter { shift @ARGV } °
or
sub iter {scalar <STDIN>} *
And use it in the loop
while ( ($id) = iter() ) { ... }
Another way could be to override readline (which is the iterator behind <> ) on demand to iterate over @ARGV.
Both ideas untested since I'm posting from mobile.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) Could be that you need
sub iter { shift @ARGV //()}
instead, I'm afraid shift will return undef if the array is exhausted.
*) updated scalar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting data from either ARGV or STDIN
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 |