in reply to Re: still confused with CGI and carriage returns carriage returns
in thread still confused with CGI and carriage returns carriage returns

It works for me:
my $string = "hi, \n\nhow are you\n?"; $string =~ tr/\n/X/; print ">>$string<<\n";
Result: >>hi, XXhow are youX?<<
  • Comment on RE: Re: still confused with CGI and carriage returns carriage returns
  • Download Code

Replies are listed 'Best First'.
RE: RE: Re: still confused with CGI and carriage returns carriage returns
by perlmonkey (Hermit) on Apr 26, 2000 at 20:59 UTC
    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.