unix pipes to perl scripts

T

trt.

Got a problem piping command output to a perl script, in the test below
the loop accepts the piped files but it also interferes with my STDIN!

===test=============================
$ls -1 *.cfg | ./pp
ls -1 *.cfg | ./pp
file: hosts.cfg
file: pseries.cfg

type something : you typed :
===test=============================

I do not get the chance to type something in after "type something"...

Do i have to flush some variable inbetween the foreach loop and
<STDIN>?
Is looping trough <ARGV> or <> the best way to catch piped input?

===code=============================
$cat ./pp
#!/usr/bin/perl

while ( <ARGV> ) {
print "file: $_";
};

print "\ntype something : ";
$answer = <STDIN>;
print "you typed : $answer \n";
===code=============================

thanks!
 
M

Michael Abootorab

how about this

$ls -1 *.cfg | perl -ne '
print "file: $_";
while(<> ){
print "file: $_";
};
print "\ntype something : ";
$answer = <STDIN>;
print "you typed : $answer \n";
'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top