
FiMko
New User
Jan 11, 2010, 8:47 AM
Post #1 of 3
(1761 views)
|
|
Using variable $& for getting result
|
Can't Post
|
|
Hi all! I need your help in very simple problem. I have a file content like: And I have a perl script parsing this file:
if(scalar(@ARGV) == 0) { print "None of file paths is specified!"; exit; } # for all the specified files for ($i = 0; $i < @ARGV; $i++) { $file_path = $ARGV[$i]; open(IN, $file_path) || die; # read next file while ($line = <IN>) { $line =~ m/^[^\s].+$/; print $& . "\n"; } close (IN); } So, I expect the following out: But have the following: In the second pass the regular expression does not match a text, but variable $& keeps its value from the previous pass ("string1"). This is printed out. What should I do in such cases? I can't clear variable $& as it is readonly. Could you please give me a hint, I can't find an info in any guide. Thanks in advance!
(This post was edited by FiMko on Jan 11, 2010, 8:50 AM)
|