On 11-03-30 11:10 AM, siegfr...@heintze.com wrote:
I apologize if this appears twice. Since I sent it once and forgot to
abandon HTML in favor of plain text, I'm sending it again.
This works:
$ perl -e ' $s =<STDIN> ; print "$s\n"; '
I don't like it because<STDIN> is hard coded. What if I want to
conditionally read from a file?
Here is my attempt to store it in a variable but it does not work with
ActiveState Perl:
$ perl -e ' local X; X =<STDIN> ; $s = X ; print "$s\n"; '
Can't modify constant item in local at -e line 1, near "X;"
Execution of -e aborted due to compilation errors.
What is the syntax? Is<STDIN> a file handle in perl?
Try:
#!/usr/bin/env perl
use strict;
use warnings;
my $fh;
if( @ARGV ){
open $fh, '<', $ARGV[0] or die "could not open $ARGV[0]: $!\n";
}else{
$fh = \*STDIN;
}
while( <$fh> ){
printf "%5d: %s", $., $_;
}
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/