Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
There's more than one way to do things
 
PerlMonks  

Re: Can a string be a file hanle?

by CombatSquirrel (Hermit)
on Sep 26, 2004 at 18:46 UTC ( [id://394019]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Can a string be a file hanle?

Yes it can, have a look at perldoc -f open:
sub subroutine { my $fh = shift; print $fh "Hello, filehandle!\n"; } my $dest; open my $fh, '>', \$dest; subroutine($fh); close $fh; print "\$dest is '$dest'";
Cheers,
CombatSquirrel.

Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re^2: Can a string be a file hanle?
by JediWizard (Deacon) on Sep 26, 2004 at 19:14 UTC

    That is a cool trick. I looked in opentut and open and didn't see any indication that such a thing was possible. Where did you find out you could do this?

    May the Force be with you
      If you look about a third of the way down on the "open" man page that you linked to in your own reply, you'll find the part that describes how 'File handles can be opened to "in memory" files held in Perl scalars...'

      Stringstreams were introduced somewhere near perl 5.8. Check if you have a new enough perl. If you didn't see this in perlfunc or perlopentut, you might have a too old version.

        That is the problem. I was looking at the docs for Perl 5.6.1. I also have 5.8.0 installed on my machine, and looking at the docs for that, I do see the Stringstreams mentioned.

        Thank you ambrus.

        May the Force be with you

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394019]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.