Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How do I treat a string like a filehandle?

( #32768=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I treat a string like a filehandle? contributed by indigo

Use a pipe:
#!/usr/bin/perl -w use FileHandle; use strict; my $string =<<EOD; One fish Two fish Red fish Blue fish EOD my $fh = new FileHandle("echo \'$string\' |") or die; print $_ while <$fh>;

Comment on Answer: How do I treat a string like a filehandle?
Download Code
RE: Answer: How do I treat a string like a filehandle?
by merlyn (Sage) on Sep 16, 2000 at 04:25 UTC
    No point in invoking a shell there, when this will do:
    my $fh = FileHandle->new or die "Cannot create filehandle: $!"; defined(my $pid = open($fh, "-|")) or die "Cannot fork: $!"; unless ($pid) { print <<'EOD'; One fish Two fish Red fish Blue fish EOD exit 0; } print $_ while <$fh>; # in parent
    But again, this forks (as does yours), and it's much better to use IO::Stringy to do it all within one process.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-08-23 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls