Kathryn Bushley wrote:
>
Hi, I'm trying to do a substitution and am having trouble in that I am
getting non-specific matches...I'd like to specify the regular expression to
match any character to the left of $code and nothing or the end of the array
element on the right of $code...is there a character class or some other way
to specify the end of the array element?
thanks,
keb
For an array @TREE, the gist of the substitution is this
#if ($TREE[$n] =~ m/(.*)$code/) {print "MATCH"." ".$code."VALUE->".$id_global{$code}."<-\n";}else {print
"NO MATCH" ." ".$code."<-\n";} #works,matches all values w/right val
$TREE[$n] =~ s/(.*)$code/$1$id_global{$code}/; #Yea!...now it substitutes
one value correctly
}
#print $TREE[$n].":"."\n";
$n++;
$count++;
}
}
print $TREE[$n].":";
Hello Kathryn
It depends on what you mean by 'nothing'! Some data examples would help, but I
think you want this:
$TREE[$n] =~ s/$code$/$id_global{$code}/;
An array element is simply a scalar variable. A dollar sign will match the end
of a string or before a terminating newline character.
Even if this works, can you tell us a little more please? I think you may be
looping through multiple values of $code when you don't need to.
By the way, you don't need all those concatenation operators in there.
print "MATCH"." ".$code."VALUE->".$id_global{$code}."<-\n";
is the same as
print "MATCH $codeVALUE->$id_global{$code}<-\n";
and
print $TREE[$n].":"."\n";
is the same as
print "$TREE[$n]:\n";
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>