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. Advertisements

  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. Advertisements

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. dpackwood
    Replies:
    3
    Views:
    2,175
  2. Ganesh
    Replies:
    4
    Views:
    477
    Thomas Weidenfeller
    Jan 31, 2005
  3. potato

    Java and UNIX pipes

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

    Perl scripts for Unix on my windows machine

    Ren Patterson, Oct 14, 2003, in forum: Perl Misc
    Replies:
    23
    Views:
    506
    Eric Bohlman
    Oct 17, 2003
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    574
    Michele Dondi
    Jan 22, 2004
  6. trt.

    unix pipes to perl scripts

    trt., Mar 14, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    299
    Chris Mattern
    Mar 14, 2005
  7. Larry
    Replies:
    9
    Views:
    376
    samwyse
    Jul 20, 2005
  8. Replies:
    13
    Views:
    821
    Anno Siegel
    Sep 10, 2007
Loading...