in reply to strange thing in perl's eval function(solved))

There are several things that are not efficient in your script as shown in your OP.

  1. why assign "matched" string before going over the string? Only to check it using an "eval" string.
  2. You are chomping the string twice for what reason?
    Why not do:
    while (my $line=<DATA>) { chomp($line);..
  3. finally, you don't want to be using $&, $' and $` in your program.
    Check perlfaq6 on your system as perldoc perlfaq6
    OR check Here
Something like this could help:
#file: test.pl #!/usr/bin/perl -w use strict; use v5.10; my $pattern = qr/test/; while (my $line=<DATA>) { chomp($line); $line =~ /($pattern)/p; my $result = $line. ' => matched:'.${^MATCH}.$/; print $result; } __DATA__ test1a.txt test1b.txt test1c.txt

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: strange thing in perl's eval function
by a369 (Initiate) on Jun 07, 2013 at 07:59 UTC
    1. Just because if removing the first one, warning appears, an answer on StackOverflow has cleared this problem. 2. Because sometimes $_ changes unpredictable, I used another variable but forgot to remove the first chomp. 3. Good suggestion. I hope perl6 will mature soon, not just on VM.