Home > Archive > PERL Beginners > April 2004 > Regexp matching problems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Regexp matching problems
|
|
| Jason Price 2004-04-27, 12:26 am |
| I am having problems with one of my regexp substitutions not matching =
the first line returned in a set, and I'm having trouble figuring out =
why. I figure there's probably a hidden system character or something =
of the sort that is causing my regexp to fail.
Here's the scenario:
I'm forking off children from a parent, calling a remote script in each =
child. The remote script sends its results to STDOUT, which I'm =
capturing via pipes. The data from each child needs to be kept =
separate, so I'm prepending a tag to each line before printing to STDOUT =
($servers[$c] spits out the server name):
print "%%%%" . $servers[$c] . "%%%%" . $_;
Output from all children is captured into an array, and then split out =
into arrays based on each server name, removing the custom tag ($1 is =
the server name):
while(<READER> ) {
if ($_ =3D~ s/^%%%%(\w+)%%%%//) {
push @{$1}, $_;
}
}
I then proceed to format my output and print results on a per-server =
basis. The problem is that it appears that the first line returned to =
the parent array does not match my substitution regexp above, and the =
custom tag remains in place. Additionally, this only happens when more =
than one child process is spawned - with just one child, it works fine. =
Reading what I just wrote, maybe it's the first line returned from =
children finishing 2nd or later.
If I change the substitution regexp to:
if ($_ =3D~ s/^.*%%%%(\w+)%%%%//)
everything works perfectly. The only thing I can think of is that some =
system character is hiding between the ^ and my custom tag, but I can't =
seem to figure out what it is. Is there a way I can view system =
characters in a variable?
Probably not the best explanation, but hopefully that all makes sense. =
Any input as to what the issue might be, or how I might idendify or fix =
it?
Thanks.
Jason
| |
| Randy W. Sims 2004-04-27, 12:26 am |
| On 4/26/2004 4:27 PM, Price, Jason (TLR Corp) wrote:
> Is there a way I can view system characters in a variable?
my $str = "\n\r\bHello, World!\n";
printf( "%02x ", ord $_ ) for split //, $str;
|
|
|
|
|