unix pipes to perl scripts

Discussion in 'Perl' started by trt., Mar 14, 2005.

  1. trt.

    trt. Guest

    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!
    trt., Mar 14, 2005
    #1
    1. Advertising

  2. how about this

    $ls -1 *.cfg | perl -ne '
    print "file: $_";
    while(<> ){
    print "file: $_";
    };
    print "\ntype something : ";
    $answer = <STDIN>;
    print "you typed : $answer \n";
    '
    Michael Abootorab, Mar 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ganesh
    Replies:
    4
    Views:
    365
    Thomas Weidenfeller
    Jan 31, 2005
  2. potato

    Java and UNIX pipes

    potato, Jul 22, 2005, in forum: Java
    Replies:
    3
    Views:
    608
  3. Ren Patterson

    Perl scripts for Unix on my windows machine

    Ren Patterson, Oct 14, 2003, in forum: Perl Misc
    Replies:
    23
    Views:
    260
    Eric Bohlman
    Oct 17, 2003
  4. trt.

    unix pipes to perl scripts

    trt., Mar 14, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    149
    Chris Mattern
    Mar 14, 2005
  5. Replies:
    13
    Views:
    513
    Anno Siegel
    Sep 10, 2007
Loading...

Share This Page