John W. Krahn wrote:
M. Kristall wrote:
John W. Krahn wrote:
open INPUT, '<', 'record.txt' or die "Error, can't open 'record.txt'
$!";
while ( <INPUT> ) {
next unless /^\?/;
print "$1\n" if /<([^>]+)>/;
}
close INPUT;
We want some line numbers (and I like parens):
As long as you realise that putting a space between the operator name
and the
left parenthesis may trigger a warning when warnings are enabled. (And
you DO
have warnings enabled, don't you?)
$ perl -le'use warnings; print( 1,2,3,4,5 )'
12345
$ perl -le'use warnings; print ( 1,2,3,4,5 )'
print (...) interpreted as function at -e line 1.
12345
...
$ perl -le"user warnings; print ( 1,2,3,4,5 );"
12345
Also, using parentheses on the left hand side of an assignment forces list
context on the right hand side of the assignment.
my ($line) = 1;
open (FILE, '<record.txt') or die ("Blah blah: $!");
while (<FILE>) {
next unless m/^\?/;
print ($line++, ": $1\n") if m/<(.*)>/;
# Is there any reason for this not to be greedy?
}
close (FILE);
John
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>