'extracting' from a string via regular expressions?
- From: sseelenluft@xxxxxxxxx
- Date: Mon, 13 Oct 2008 07:53:34 -0700 (PDT)
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.
.
- Follow-Ups:
- Re: 'extracting' from a string via regular expressions?
- From: Tim Greer
- Re: 'extracting' from a string via regular expressions?
- From: Tad J McClellan
- Re: 'extracting' from a string via regular expressions?
- From: smallpond
- Re: 'extracting' from a string via regular expressions?
- From: Jürgen Exner
- Re: 'extracting' from a string via regular expressions?
- From: Klaus
- Re: 'extracting' from a string via regular expressions?
- From: Josef Moellers
- Re: 'extracting' from a string via regular expressions?
- Prev by Date: Re: Odd behaviour with has key - wide character
- Next by Date: Re: Help: How to process output of a program
- Previous by thread: Help: How to process output of a program
- Next by thread: Re: 'extracting' from a string via regular expressions?
- Index(es):
Relevant Pages
|