Re: extract a value from a field in a file
- From: nufin <nufin>
- Date: Wed, 29 Jun 2005 20:18:27 +0200
Hi Mark,
Many thanks for your help ! I will test it and follow your recommandations. Best Regards, Christophe
Mark wrote:
nufin wrote:
Hello,
I need to extract from a file values of the "QRKPageBegin" field. Into the file, the fields appear like following: %%QRKPageBegin: 2 %%QRKPageBegin: 4 %%QRKPageBegin: 5
I would like to extract each of the values of this field, to set a list.
Actually, (I am a perl newbie), I wrote the following code
open (PS,$PSFile) or die "Could not open the file $PSFile: $! \n"; $/ = "\r";
while (<PS>) { while (/([%%QRKPageBegin\s]{14,})/g) { print $1, "\n"; } } close PS;
However it display/get the field but not the value, so any help would be greatly appreciated !
For a start, make sure that you have
use warnings; use strict;
at the top of every Perl script. This will catch a lot of otherwise hard-to-find errors.
You've misunderstood regular expressions (or at least partly misunderstood). [] defines a character class - you have no need for this here. You need a regex like
/^%%QRKPageBegin:\s*(\d+)$/
assuming that this is all that will appear on one line. Putting
use re 'debug';
at the start of your script will help you to debug regexs. See
perldoc re
for more details on this and
perldoc perlre
for general information about regexs.
regards,
Mark
.
- References:
- extract a value from a field in a file
- From: nufin
- Re: extract a value from a field in a file
- From: Mark
- extract a value from a field in a file
- Prev by Date: Re: Simple Structure Question
- Next by Date: How to redirect to webpage using perl?
- Previous by thread: Re: extract a value from a field in a file
- Next by thread: Re: extract a value from a field in a file
- Index(es):