R
rsarpi
Sorry the dumb question. I'm a newbie.
But how can I search and replace a string while preserving (not
removing) trailing spaces?
let me explain: the command 's/$old_string/$new_string/g' inserts the
new string and *moves* spaces to the right or left (depending on the
length of the 'new_string') making the whole sentence bigger or
smaller.
for example:
my $sentence = "*Peter Parker is Spider Man *";
print length($sentence); #prints 43 characters
I'd like to know a trick in which, if I get rid of "Peter" I would
_still_ get 43 characters in length for the whole sentence between
both quotation marks. Here the whole sentence between quotation marks
expands until it reaches 43 chars in length.
my $sentence = "*Parker is Spider Man *";
print length($sentence );#still 43
And if I add to the sentence Benjamin (between Peter and Parker) I
would like to get exactly 43 characters between both quotation marks.
Here the whole sentence between quotation marks shrinks until it gets
up 43 chars in length.
my $sentence = "*Peter Benjamin Parker is Spider Man *";
print length($sentence ); #still 43
But how can I search and replace a string while preserving (not
removing) trailing spaces?
let me explain: the command 's/$old_string/$new_string/g' inserts the
new string and *moves* spaces to the right or left (depending on the
length of the 'new_string') making the whole sentence bigger or
smaller.
for example:
my $sentence = "*Peter Parker is Spider Man *";
print length($sentence); #prints 43 characters
I'd like to know a trick in which, if I get rid of "Peter" I would
_still_ get 43 characters in length for the whole sentence between
both quotation marks. Here the whole sentence between quotation marks
expands until it reaches 43 chars in length.
my $sentence = "*Parker is Spider Man *";
print length($sentence );#still 43
And if I add to the sentence Benjamin (between Peter and Parker) I
would like to get exactly 43 characters between both quotation marks.
Here the whole sentence between quotation marks shrinks until it gets
up 43 chars in length.
my $sentence = "*Peter Benjamin Parker is Spider Man *";
print length($sentence ); #still 43