Hi,
Thank you for looking to help me. Unfortunately, when I used your code nothing
was extracted. At least when I printed $1 nothing appeared.
In order to help me learn more about Perl - I'd like to know why my code didn't
work. If I understand your code correctly then I should see:
$1 = Abc123, $2 = STATUS, $3 = open, $3 = DESCRIPTION, etc.
While anything would be better than my puny effort, I was looking just to
extract the "data" - in other words:
$1 = "Abc123", $2 = "open", $3 = "a basket of melons", $4 = "1".
I thought I was successfully copying from a similar script - but obviously I
don't have enough understanding in order to make it work. If I take my code
apart, I thought that:
\STATUS\s+(\w+)\s+ would extract the word between STATUS and
DESCRIPTION, and
\{\s+fruittype\s+(\d+)\s+} would extract the number following
"fruittype"
Individually they do - it is just when I add then together in the same line
that I receive nothing. What am I doing wrong?
Chris
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 25 May 2012 11:53 PM
To: Christopher Gray; [email protected]
Subject: RE: Help required to extract multiple text fields from a text string
May you try this matching?
while(<DATA>) {
next unless /^(\S+\s+)(\S+\s+)(\S+\s+).*\"(.*?)\"/;
print "$1 $2 $3 $4\n";
}
HTH.
========================================
Message Received: May 25 2012, 09:52 PM
From: "Christopher Gray" <[email protected]>
To: [email protected]
Cc:
Subject: Help required to extract multiple text fields from a text string
Good day,
I have a text file containing records. While I can extract single
sub-strings, I cannot extract multiple sub-strings.
The records are of multiple types - only about a third of which have the data
I need.
An example of a "good" record is
Abc1234 STATUS open DESCRIPTION "A basket of melons" :: { fruittype 1}
I'm trying to extract the first (Abc1234), second (open), third (A basket of
melons) and fourth (1) strings.
I can extract each of them separately - but not together.
So - for example:
while (<FILE>) {
chomp;
next if !/\{\s+fruittype\s+(\d+)\s+}/;
my $Temp =$1;
}
Extracts the fruittype. However, when I try and have multiple extracts:
...
next if !/\STATUS\s+(\w+)\s+\{\s+fruittype\s+(\d+)\s+}/;
...
It fails.
What have I done wrong?
Chris
--
To unsubscribe, e-mail: [email protected] For additional
commands, e-mail: [email protected] http://learn.perl.org/
--
To unsubscribe, e-mail: [email protected] For additional commands,
e-mail: [email protected] http://learn.perl.org/
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/