Re: matching the end of an array element



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"


.



Relevant Pages

  • Re: Easy balanced tree
    ... The tree can hold between 4 and 7 values, if it was lower than 4 ... then the array would be smaller so we ignore those cases. ... Secondly there is wasted space in the middle of the array (with ... rdrop nip nip; ...
    (comp.lang.forth)
  • Re: Is it possible to have mutable-in-place (associative-)array objects in PHP?
    ... This is the way all languages work. ... just that array variables aren't objects ... and for each I must find the appropriate path in the tree I'm ... treeptr <- rootOfTree ...
    (comp.lang.php)
  • Re: [opensuse] Recover md RAID-1.
    ... md: md0 stopped. ... Then try booting the array with just /dev/sdb1 as a member. ... A ball hitting a tree shall be deemed not to have hit the tree. ...
    (SuSE)
  • Re: data structure for network protocol
    ... As a first thought, I was considering linked lists, but they are probably ... The second option is tree. ... hash tables. ... in an ordinary array (the main cost is that, if the number of items gets ...
    (comp.programming)
  • Re: array moving left
    ... I have an array in which elements are present. ... Instead maintain a binary tree of deletion points. ... The left child weight of a node is the number of nodes under it on the ... deletions have occurred to the left of the element. ...
    (comp.programming)