Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: outputs followed by each other

by BillKSmith (Monsignor)
on Feb 17, 2018 at 16:48 UTC ( [id://1209391]=note: print w/replies, xml ) Need Help??


in reply to outputs followed by each other

Even on simple programs like this, CPAN modules can be a big help. In the following example, the modules require little additional code, but greatly extend the capability. The IO::Prompt::Hooked not only takes care of the newline problem, it validates the input, and gives the user another chance if it is not valid. (There are more options available that you may wish to experiment with.) Regexp::Common extends the validation to allow any valid real number format.
#! /usr/bin/perl -l use strict; use warnings; use IO::Prompt::Hooked; use Regexp::Common; my %opt = ( message => "please enter a number: ", validate => qr/^$RE{num}{real}$/, error => "Input must be a number\n", ); my $n1 = prompt(%opt); my $n2 = prompt(%opt); if ($n1 <= $n2) { print "$n1 <= $n2\n" ; } else { print "$n2 <= $n1\n" ; }
Bill

Log In?
Username:
Password:

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

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

    No recent polls found