in reply to read a word from a line
Hi,
Try :
output:while(<PAGE>) { if (/pond.*\((\w+)\)/) { print "$1\n"; } } close(PAGE);
start end
$_ is the default scalar variable. In your while loop, when you read the file, you are NOT specifying any variable to hold the line read from file. So its kept in $_. Again for your regular expression, you are not specify any string/variable to match with. So it again match with $_. So when you print $_, it prints entire line. Again, $1 contains the first matching string. For details please have a look at perlre and perlvar
The above code is same as
or can be written without relying on $_ aswhile($_ = <PAGE>) { if ( $_ =~ /pond.*\((\w+)\)/) { print "$1\n"; } } close(PAGE);
my $line; while($line = <PAGE>) { if ($line =~ /pond.*\((\w+)\)/) { print "$1\n"; } } close(PAGE);
Cheers !
--VC
|
|---|