Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

piping previous command's output into perl 2

Status
Not open for further replies.

DIEBEL

Programmer
Oct 16, 2009
1
CA
I wish to pipe the output of the previous commond in a pipeline into my perl script.
How is this generally best done?

Thanx
 
And to read the piped input, you can use the "diamond operator", i.e. <>, for example, the following code will simply print it out.

Code:
while (<>) { print; }

Annihilannic.
 
Another way...
Code:
#!/usr/bin/perl

use strict;

open( my $ls_output, '-|', 'ls' )
  or die "Cannot execute ls - $!";

print "$_\n" while (<$ls_output>);
close( $ls_output );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top