http://www.perlmonks.org?node_id=1066465


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