On Feb 20, 2006, at 0:39, Bowen, Bruce wrote:
A possible idiom is:
my @lines = <>; # slurp all lines
my @wanted = grep { m'012,D|011,@D' } @lines;
*********************************************
I tried
open STATE, "STATEFILE.txt" or die
my @lines = <STATE>;
my $state = grep {m"011.,"} @lines
print "state = ", $state, "\n";
And I get state = 1
No errors but not the output I'm looking for.
Note that there was an array @wanted in my example, that makes a
difference:
open my $st, "STATEFILE.txt" or die $!;
my @lines = <$st>;
close $st;
my @states = grep { /011.,/ } @lines;
print "state = $_" for @states;
That can be done in the command line as well (the example uses Unix
shell quotes, adapt to Windows if needed):
$ perl -ne 'print qq(state = $_) if /011.,/' < STATEFILE.txt
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>