M
Michael Friendly
This is probably simple, but I can't find it...
I frequently write scripts to take input from STDIN or from a named file
by doing
open(STDIN, "<$opt_i") or die "-i $opt_i: can't open.\n" if $opt_i ;
...
while (<>) {
}
but how can I read from <DATA> if no file is given on the command line?
undef $/; # slurp whole file
my $lines = @ARGV ? <> : <DATA>;
will work, but I need to read in a while loop.
--
Michael Friendly Email: (e-mail address removed)
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA
I frequently write scripts to take input from STDIN or from a named file
by doing
open(STDIN, "<$opt_i") or die "-i $opt_i: can't open.\n" if $opt_i ;
...
while (<>) {
}
but how can I read from <DATA> if no file is given on the command line?
undef $/; # slurp whole file
my $lines = @ARGV ? <> : <DATA>;
will work, but I need to read in a while loop.
--
Michael Friendly Email: (e-mail address removed)
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA