Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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>;

Replies are listed 'Best First'.
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 cooling their heels in the Monastery: (7)
As of 2016-06-26 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (327 votes). Check out past polls.