'extracting' from a string via regular expressions?



Hi,
I was modifying code written by others when something stopped working.
I was using a construct like:
$string=~ m@PartOne(.*)PartTwo@;
to find and extract everything between 'PartOne' and 'PartTwo', and I
swear it was working. Then I moved to a different string and it
stopped working (and now the first example also stopped working).
Below is a not-working test-case:

#! /usr/bin/perl

use strict;

# Definition of variables
my $line;
my $file;

# Read file
@ARGV = qw# test2.csv #;
while (defined($line = <>)) {
$file .= $line;
}

$file=~ m@TEMPLATES(.*)ONLY@;

print $file . "\n";

The file test2.csv contains just one sentence: 'IMPORTANT: THESE
TEMPLATES MAY ONLY BE USED WITH THE WRITTEN PERMISSION'
Therefore, the code above should print simply 'MAY' (possibly with the
spaces), but it prints the whole sentence.

Finding the word 'TEMPLATES' works fine, a la:
if ($file=~ m@TEMPLATES@) {
print "It matched!" . "\n";
}
works fine.

So, what am I missing here?
Thanks.

.



Relevant Pages

  • Problems with WebRequest and Connection
    ... I am using HttpWebRequest to resolve an external URL (that outputs an XML ... network related services seem to be working. ... frustrating thing is that it recently worked - once - then stopped working ... private string readHtmlPage ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: extracting from a string via regular expressions?
    ... I was modifying code written by others when something stopped working. ... Then I moved to a different string and it ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (comp.lang.perl.misc)
  • Re: extracting from a string via regular expressions?
    ... I was modifying code written by others when something stopped working. ... to find and extract everything between 'PartOne' and 'PartTwo', ... Then I moved to a different string and it ... use strict; ...
    (comp.lang.perl.misc)
  • Issues with appending String - Simple, but VERY frustrating
    ... I'm using the same methods I've been using all through out my script, and its stopped working for this one function. ... When I output to an Echo Window, ... I've also tried putting them into an Array and using the Join Function, that, as well, returned the shortened string. ...
    (microsoft.public.scripting.vbscript)
  • Re: Issues with appending String - Simple, but VERY frustrating
    ... Password = "PasswordX" (string) ... > and its stopped working for this one function. ... >> When I output to an Echo Window, ... > an Array and using the Join Function, that, as well, returned the ...
    (microsoft.public.scripting.vbscript)