Here's an (almost) one-line solution.
It took a few minutes, but this looks like a good prototype
for your needs. You will likely need to adjust the tests on the
position variable $i to fit your need more
precisely...
use strict;
my $str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n';
print "$str\n";
my $i = 0;
$str =~ s/(.)/$i++;($1 ne ',' or $i>15 && $i<25) ? $1 : '#'/ge;
print "$str\n";
This prints:
a,b,c,d,e,f,g,h,i,j,k,l,m,n
a#b#c#d#e#f#g#h,i,j,k,l,m#n
I used '#' instead of "\t" for demo purposes so things
would line up nicely in the print test.
Note: along the way I tried using pos
instead of $i, but
apparently it is undefined while still in
the right side of the s///.
Update: Hofmator
is correct to say I am wrong to imply that pos
would work outside the
s///.
pos is not set at all for s///.
Note 2: I offer this as a solution to the problem
as you described it but it seems very odd that
you would have a list of companies with names that are
exactly 10 characters long. |