Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
P is for Practical
 
PerlMonks  

Re: how to print only 47 and another number will rejected and when user give 47 that number only print ?

by Kenosis (Priest)
on Dec 10, 2013 at 16:45 UTC ( #1066465=note: print w/ replies, xml ) Need Help??


in reply to how to print only 47 and another number will rejected and when user give 47 that number only print ?

Here's another option:

use strict; use warnings; my $num; do { chomp( $num = <> ); } until $num eq '47'; print $num;

This keep's doing the code block (getting input from STDIN) until $num is 47. $num's printed only if it's 47. Why a eq instead of a ==? If 'asdf' is entered when using a ==, you'll get an Argument "asdf\n" isn't numeric in numeric eq (==) at ... messsage, but not if eq is used.

Did you want stealth? The following will not echo anything to the screen until 47 is entered, and then 47 will be printed:

use strict; use warnings; use Term::ReadKey; my $num; ReadMode 'noecho'; do { chomp( $num = ReadLine(0) ); } until $num eq '47'; ReadMode 'restore'; print $num;

Hope this helps!


Comment on Re: how to print only 47 and another number will rejected and when user give 47 that number only print ?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-04-21 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls