in reply to using a variable as a filehandle

See open for the scoop on opening filehandles to stuff you already have in memory.</code>

open my $fh, "<:raw:scalar", $record{'data'} or die "Couldn't open memory file: $!";

Replies are listed 'Best First'.
Re^2: using a variable as a filehandle
by itub (Priest) on Nov 01, 2004 at 18:45 UTC
    Note: This requires perl-5.8.0 or greater.
Re^2: using a variable as a filehandle
by bear0053 (Hermit) on Nov 01, 2004 at 18:55 UTC
    what is wrong with this: I am running perl 5.8.1.
    open (RF,"<:raw:scalar", $$record{data}) or die "Couldn't open memory + file: $!"; while(my $line = <RF>){ print "\n in while \n"; } close(RF);
    It doesn't die. (i verified there is data in the variable) and it never prints "in while" so it appears <> is finding no lines. any ideas thanks again

    Thanks! Its cool you can read from memory like filehandle (learn something enw everyday!!!) Once i get it to work i will be thrilled!!

      You might try changing the :raw to :crlf. Try also setting $/ to \n.

      open my $fh, "<:crlf:scalar", $record{'data'} or die ...; { local $/ = "\n"; while ( my $line = <$fh> ) { print "in line\n"; } }