Re: matching the end of an array element
- From: mumia.w.18.spam+nospam@xxxxxxxxxxxxx (Mumia W.)
- Date: Tue, 31 Oct 2006 18:49:20 -0600
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"
.
- References:
- matching the end of an array element
- From: Kathryn Bushley
- matching the end of an array element
- Prev by Date: Re: Naive Bayes classification module of CPAN
- Next by Date: Re: Problrm compiling GD
- Previous by thread: Re: matching the end of an array element
- Index(es):
Relevant Pages
|