Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: A readline + -e oddity: readline opens files even with -e --- need "readline STDIN" to read from console

by haukex (Archbishop)
on Nov 30, 2020 at 16:50 UTC ( [id://11124404]=note: print w/replies, xml ) Need Help??


in reply to A readline + -e oddity: readline opens files even with -e --- need "readline STDIN" to read from console

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.

  • Comment on Re: A readline + -e oddity: readline opens files even with -e --- need "readline STDIN" to read from console
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found