On Mon, Sep 03, 2012 at 08:56:13AM -0700, Kendall Conrad wrote:
> #!/usr/bin/perl
> my $str = '\bthe\b';
> my $iter = 0;
> while (<>) {
> if ($_ =~ m/${str}/){
> my $n1 = $_;
> while ($n1 =~ m/(${str})/) {
> $iter++;
> $n1 =~ s/(${str})/$1${iter}/;
> }
> print $n1;
> }
> else {
> print "$_";
> }
> }

I hope Kendall won't mind if I suggest a version using more idiomatic Perl:

#!perl

my $re = qr/\bthe\b/;
my $iter = 0;
while (<>) {
  s/($re)/ $1 . ++$iter /ge;
  print;
}

Ronald

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to