in reply to Re: Increase number per regex replacement
in thread Increase number per regex replacement

Ah, but what if you needed to use "fee.$i" as the replacement string instead of "foo.$i"?

Fee fi foo fum, I smell the infinite loop of an eratum...

-Blake

  • Comment on Re: Re: Increase number per regex replacement

Replies are listed 'Best First'.
Re: Re: Re: Increase number per regex replacement
by belg4mit (Prior) on Jan 08, 2002 at 11:02 UTC
    True true, but this was meant to be a whimscial/goldbergian solution. You'd have to be wary of the same issue with /e though not /ge ;-) Of course this fixes that:
    $i = 0; @no = qw(one two three four five); foreach ( @no ){ my $str = ''; while( s/([^e]*)e// ){ $str .= $1 . "fee" . $i++; } $_ = $str . $_; #UPDATED: Append addresses Re: to this node } print "@no\n";

    --
    perl -pe "s/\b;([st])/'\1/mg"

      Hmmm... I don't mean to keep poking at a not-too-serious answer, but I don't think that works exactly right either. What happens with numbers like 'seven' or 'ten' that have an 'e' in the middle, but not at the end? The last non-matching-non-'e' part gets removed.

      Update: for that matter, the numbers w/o an 'e' in them at all are being nulled out...
      Update2: Updated code now seems to work properly, $str is built up while $_ is torn down...

      -Blake