in reply to Having Trouble Removing a Newline from a Multiline String

$ matches the point between \n and the character before it.

print "a\n\nc\n" =~ / a\n ^ $ c\n /mx ?1:0, "\n"; # 0 print "a\n\nc\n" =~ / a\n ^ $ \n c\n /mx ?1:0, "\n"; # 1

Since $ matches before the newline, it doesn't ever actually match the newline, and thus the newline is not getting substituted. What you want to do is remove newlines that start lines.

$_ = "abc\n" . "def\n" . "\n" . "jkl\n" . "\n" . "\n" . "stu\n"; s/^\n//mg; print;
abc def jkl stu

Replies are listed 'Best First'.
Re^2: Having Trouble Removing a Newline from a Multiline String
by Dru (Hermit) on Oct 02, 2008 at 07:11 UTC
    That did the trick, thank you.

    Thanks,
    Dru

    Perl, the Leatherman of Programming languages. - qazwart