You might be interested in what Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin and the corresponding part of PBP has to say about it. Also, you might want to consider checking via IO::Interactive to see if the terminal is actually interactive.

use warnings; use strict; use IO::Interactive 'is_interactive'; use Term::ReadLine; print "Hello, World!\n"; if ( is_interactive() ) { print "Press Enter to continue...\n"; Term::ReadLine->new("")->readline(""); } else { warn "Noninteractive, continuing...\n" }

This will prompt the user to press enter if connected to a terminal, but if the script is used in a non-interactive environment (simple example: perl script.pl | cat), it won't. See also other prompting alternatives.


In reply to Re: A readline + -e oddity: readline opens files even with -e --- need "readline STDIN" to read from console by haukex
in thread A readline + -e oddity: readline opens files even with -e --- need "readline STDIN" to read from console by cxw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.