Okay so I am an ass yet again. I did try it on my system before
I rambled and the tr did not work, so I must have had a dumb little typo.
Just for kicks I benchmarked the s/// vs tr/// since they
seem to do the same in this reguard:
use Benchmark;
$str = "\n#\n#\nSTUFF\n#\n#\n";
timethese(1000000, {
's' => sub { $a = $str; $a=~s/\n/ /g; },
'tr' => sub { $a = $str; $a=~tr/\n/ /; }
});
RESULTS:
Benchmark: timing 1000000 iterations of s, tr...
s: 11 wallclock secs (11.22 usr + 0.00 sys = 11.22 CPU)
tr: 3 wallclock secs ( 3.61 usr + 0.00 sys = 3.61 CPU)
The moral of the story: Use tr/// where you can. |