in reply to Nicest way of getting STDIN a beauty contest

magic-diamond <> behavior -- WHAT?!
  • Comment on Re: Nicest way of getting STDIN a beauty contest

Replies are listed 'Best First'.
Re^2: Nicest way of getting STDIN a beauty contest
by mickep76 (Beadle) on Oct 09, 2009 at 09:01 UTC

    It will wait in perpetuity before exiting if no input was provided to STDIN and no file was specified.

    So yes magic <> would have worked if I didn't want it to exit.

    If that was all I wanted a simple ...below... would have worked.

    my @hosts = <>;
      It will wait in perpetuity before exiting if no input was provided to STDIN and no file was specified.

      How long do you want it to wait? Your program has to wait until I'm done with the current line. How does it tell that I've not just gone away for a coffee break?

      However, if STDIN is closed (e.g. by typing ^D at a terminal, or by closing a pipe after no input) the simple solution

      chomp( my @hosts = <>); die "usage: foo hosts\n" unless @hosts;

      will do what you want.