Looks cool. I'm less familiar with the idiomatic parts. I generally try to
write it more readable so there's a chance a year later that I'll still
know what the code does. I don't use Perl much so the syntax is always
foggy.
The /e flag was new to me, but very helpful. I was trying something like
that without it, but unsuccessful. I hadn't used the qr// technique before
either so I learned some new tricks. Thanks for sharing this shortened
version.
-Kendall
On Tuesday, September 4, 2012 11:36:44 AM UTC-4, Ronald J Kimball wrote:
>
> 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>