Syntactic Confectionery Delight | |
PerlMonks |
Re: read a word from a lineby atemon (Chaplain) |
on Feb 25, 2009 at 14:17 UTC ( [id://746273]=note: print w/replies, xml ) | Need Help?? |
Hi, Try : output:
$_ 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 $_ as
Cheers ! --VC
In Section
Seekers of Perl Wisdom
|
|