in reply to Re: Newbie - convert carriage return in a variable
in thread [Solved]Newbie - convert carriage return in a variable

Thanks hippo, In this case the script will just replace the first end of line found. If I want to replace more than one as
use strict; use warnings; use Test::More tests => 1; my $have = 'foo bar'; my $want = 'foo<br /><br />bar'; $have =~ s/\n/<br \/>/; is $have, $want;
I think I need to us chomp function but It's not clear how to use it.
use strict; use warnings; use Test::More tests => 1; my $have = 'foo bar'; my $want = 'foo<br /><br />bar'; $have =~ s/\n/<br \/>/; is $have, $want; my @data=split(/\n/<br \/>/); foreach my $have (@data) { $want = $have; }
But it's not working :(

Replies are listed 'Best First'.
Re^3: Newbie - convert carriage return in a variable
by poj (Abbot) on Feb 17, 2019 at 18:09 UTC

    Add the g modifier to your regex

    #!perl use strict; my $text = 'foo bar'; $text =~ s/\n/<br \/>/g; print $text;
    poj
      Thanks @poj It's solved