$ ls | more
$ perl myscript1 | myscript2
You can do this using a pipe |. In the first example the output of the ls command is piped to more so you get the results one screenful at a time.
In the scond the output of myscript1 is piped to myscript2 which will use it as input. myscript2 of course needs to be expecting the input from myscript1
to appear in STDIN for this to work.
Hope this helps.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
| [reply] [d/l] |
| [reply] |
You're kinda vague on what the problem is, using pipes or creating a perl-program that uses STDIN as input. So perhaps you'll find my comment utterly redundant.
STDIN can be read line-by-line with:
while(<>){}
Each line is assigned to $_. Now you can print a specific line to STDOUT if it matches a centain $expression:
print if /$expression/;
Or only print the part of that line if it matches:
print $1 if /($expression)/;
Everything together
while(<>){print if /$expression/;}
You could also use a commandline thingy like:
perl -ne 'print if /myword/;'
Where -n tells Perl to automatically wrap a while(<>){} around your code.
Look at tachyons comment for pipes
| [reply] [d/l] [select] |
Well, asking the sage advice of the One True Perl Guru, Guru perldoc (perldoc -f open from the cmd line), we find this:
If MODE is `'|-'', the filename is interpreted as
a command to which output is to be piped, and if
MODE is `'-|'', the filename is interpreted as a
command which pipes output to us. In the
2-arguments (and 1-argument) form one should
replace dash (`'-'') with the command. See the
Using open() for IPC entry in the perlipc manpage
for more examples of this. (You are not allowed
to `open' to a command that pipes both in and out,
but see the IPC::Open2 manpage, the IPC::Open3
manpage, and the Bidirectional Communication entry
in the perlipc manpage for alternatives.)
and this example
open(ARTICLE, '-|', "caesar <$article") # decrypt article
+
or die "Can't start caesar: $!";
Which could just as easily be:
open(FH, '-|', "myscript.pl") or die "He's dead, Jim :$!";
while(<FH>) {
do whatever with output form myscript
}
close(FH);
So, you can snarf info from one scripts output to your script using this method, or one of the IPC::OpenX methods.
Hopefully, that'll give some help.
-Syn0 | [reply] [d/l] [select] |
One way is to use open with a pipe.
open(TWO, "| /your/second/program") or die "Dead $1\n";
Now instead of printing to STDOUT, print to the filehandle
you just made:
print TWO "data data data\n";
In your second program that data is read in as STDIN:
print while(<>);
will print out "data data data".
| [reply] [d/l] [select] |