can PERL handle multiple pipes on 1 line? (222 Views)
Reply
Honored Contributor
Rick Garland
Posts: 4,470
Registered: ‎06-25-1997
Message 1 of 3 (222 Views)
Accepted Solution

can PERL handle multiple pipes on 1 line?

Hi all:

Using perl 5.8.3 on a HPUX 11.00.

I have a perl script for helpdesk to assista in management of printers.

A new option, search all printers for a pattern
Easy enough, use grep.

elsif ($choice eq '8') {
print "Search a specific print queue - what is partial printer name? ";
$prt = ;
system "/usr/bin/lpstat -t \| grep -i $prt";
&TheMenu;
}

But if I want to add another pipe to 'more', it gives me a syntax error.

system "/usr/bin/lpstat -t \| grep -i $prt | more";


There could be hundreds of printers matching the pattern so I need to page the output. But how do I pipe to more with the above command?
Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 2 of 3 (222 Views)

Re: can PERL handle multiple pipes on 1 line?

Yes, in this case the system call is simply passed to the shell. The confusion is caused by a LF in stdin.

I'll bet this works:
$prt = "xxx";
system("lpstat -t | grep -i $prt | more")

however your example fails.

after your:
$prt = ;
add this line:
chomp($prt);
I think that will fix you.

I also notice that you escaped one of your pipe symbols but not the other; you shouldn't need an escape.
If it ain't broke, I can fix that.
Please use plain text.
Honored Contributor
Rick Garland
Posts: 4,470
Registered: ‎06-25-1997
Message 3 of 3 (222 Views)

Re: can PERL handle multiple pipes on 1 line?

Hi Clay:

Both ways work. Many thanks.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation