On 10/31/2006 04:44 PM, 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].":";
You probably want non-greedy matching, e.g.
m/(.*?)$code/
Read the doc "perldoc perlre"
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>