Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Testing <>

by kennethk (Abbot)
on Oct 03, 2011 at 15:25 UTC ( #929360=note: print w/replies, xml ) Need Help??

in reply to Testing <>

You can detect the presence of waiting input using select, like:
use strict; use warnings; my $vector = ''; vec($vector,fileno(STDIN),1) = 1; if (select($vector,undef,undef,0.01)) { while (<>) { print; } }

where I have set a 10 millisecond timeout. Might be easier and more portable though to simply pass the filename as argument, and open it yourself. Like many other unix command line tools.

Replies are listed 'Best First'.
Re^2: Testing <>
by Anonymous Monk on Oct 03, 2011 at 15:35 UTC
    That works for
    /tmp/>echo "hello world\n" | myscript
    and now called on its own doesn't hang
    but there again its not clear how a usage message could be printed out.

    But it now fails when passed a filename

    /tmp/>cat x October 2011 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /tmp/myscript x
    it doesn't print the contents of the file :-( Isn't there a simpler solution? I thought that this would have a simple, forehead slapping, solution.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929360]
[marto]: cpanm let's you install from git
[Spenser]: thanks

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2018-03-17 13:08 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (224 votes). Check out past polls.