in reply to Parsing multiline string line by line

Or you can use the same file-access mechanisms to access the string if a reference to the string is passed to  open() instead of a file name:
>perl -wMstrict -e "my $filelike = qq{Line 1\nLine 2\nLine etc.\n}; open my $fh, '<', \$filelike or die $!; while (<$fh>) { print } close $fh or die $!; " Line 1 Line 2 Line etc.

Replies are listed 'Best First'.
Re^2: Parsing multiline string line by line
by wol (Hermit) on Feb 19, 2009 at 13:59 UTC
    Ooh! A new thing! I never knew this before. (It's not mentioned in the crib-sheet page I tend to use.)

    Does it do anything with references to other types as well?

    --
    use JAPH;
    print JAPH::asString();

      The manpage for open gives open FILEHANDLE,MODE,REFERENCE as a way to call open, but, oddly, neither the manpage nor perlopentut seems to discuss it further (as far as I can see from a very quick scan of those two documents). Anyone know where this may be discussed?
Re^2: Parsing multiline string line by line
by flamey (Scribe) on Feb 19, 2009 at 14:25 UTC
    aha! i saw doing it this way a long time ago in some code online, and remembered that it was possible, but figured i'll find it again when I need it... but i couldn't find any examples again! thank you very much! :-)