in reply to A quit key when no chomp

The diamond operator (readline) slurps all of the contents when used in list context. When using standard input, the termination is (under *nix) ^D - End Of Transfer.
You'll need to read in the items one by one:
print "...\n" my @input; while (<STDIN>) { last if /^q$/; push @input, $_; } print reverse @input;

I used the regex ^q$ so the trailing newline is optional (not possible when using console input, but it is possible when piping: cat script | perl reverse.pl).

++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
    - Whreq

Replies are listed 'Best First'.
Re: Re: A quit key when no chomp
by ellem (Hermit) on Mar 03, 2002 at 07:45 UTC
    Well it took 4 hours and a trip to several perldoc pages but I understand your answer. Far better than the clunky solution I was going for; thanks!
    --
    ellem@optonline.net
    There's more than one way to do it, just don't use my way.
      That's good :)

      It might seem a bit unreasonable to give an example implementation that differs a lot without adding step-by-step explanation. But this way, you're encouraged to read documentation. And I'm sure you learned a lot more than you wanted to :).

      ++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
      Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
      -- vs lbh hfrq OFQ pnrfne ;)
          - Whreq