From: Shlomi Fish <[email protected]>
> Hi Thomas,
> 
> On Mon, 30 Jul 2012 20:23:58 +0800
> Thomas Dean <[email protected]> wrote:
> 
> > Hi there,
> > 
> > I'm wondering how to get the file handle or a reference of a file
> > object of a scalar in which stores a string.
> > 
> 
> Starting from relatively recent versions of Perl, you can simply do:
> 
> use autodie;
> 
> my $buffer = "Hello World\nGood morning\nPretty foo\n";
> open my $fh_to_string, '<', \$buffer;
> 
> And then do <$fh_to_string> and other operations.

Just to prevent confusion ... the "use autodie" is not needed to be 
able to open a "filehandle into a string". It should not have been in 
the example, because it's totally irrelevant to the point at hand.
It forces some Perl builtins to throw an exception instead of 
reporting success or failure using their return values.

Some people believe this makes the code more robust. But then people 
believe all kinds of things.

Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to