in reply to extracting lines from a string - while ignoring the \n character

I may be missing something, but I believe that the literal newlines and the embedded newlines are equivalent in $string, so there's no way to differentiate between them.

I tried to muck with $/ for a while before realising that such an approach would only work if the string was being read from somewhere rather than being located in the source code.

Will the string be defined inline in your real usage case?

-David

Replies are listed 'Best First'.
Re^2: extracting lines from a string - while ignoring the \n character
by codeacrobat (Chaplain) on Oct 29, 2007 at 19:56 UTC
    Your approach works. IO::String comes to your rescue ;-)
    $ cat test.txt bla. fasel . foo . bar. $ perl -e ' use IO::String; $str=`cat test.txt`; $fh = IO::String->new($str); $/="."; print "$_|" for <$fh>' bla.| fasel .| foo .| bar.| |

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      That's fine if you're sure that '.' == EOL is what the OP meant, but that's not clear to me.

      Maybe I misunderstood, but it seemed to me like the OP wants to distinguish between what s/he perceives to be two kinds of newline.

      -David