bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:
Code:
where testfile contains the text (with special characters shown, i.e. using 'set list' in vi):#!/usr/bin/perl -w use strict; my $test = <<"TEST"; Line1 Line3 TEST ; #this worksi - it matches and prints result if ($test =~ m{ \w+\n \n \w+ }msx) { print "Heredoc test: The line \n$test\nmatches.\n"; } open (TEST, "testfile") or die "cannot open testfile testfile - $!"; print "\n==================\nReading testfile\n"; #but this doesn't show a match ... why? while (<TEST>) { if (m{ \w+\n \n \w+ }msx) { print "reading file test: The line \n$_\nmatches.\n"; } } close (TEST);
As you can see, there's nothing special about this file.Line1$ $ Line3$
Results:
perl test2.pl Heredoc test: The line Line1 Line3 matches. ================== Reading testfile
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiline regex: heredoc vs. reading file
by japhy (Canon) on Jan 25, 2006 at 17:47 UTC | |
by ikegami (Patriarch) on Jan 25, 2006 at 17:55 UTC | |
by bowei_99 (Friar) on Jan 25, 2006 at 17:59 UTC | |
by ysth (Canon) on Jan 25, 2006 at 18:06 UTC | |
by ikegami (Patriarch) on Jan 25, 2006 at 18:02 UTC | |
by bowei_99 (Friar) on Jan 25, 2006 at 18:10 UTC | |
by ikegami (Patriarch) on Jan 25, 2006 at 18:13 UTC |