Hello busyvish,

Welcome to the Monastery. Fellow Monks has already answered your question, but since you said that you are a beginner I would like to add something minor here that I think it will help you in future also. Always always use strict and warnings on your scripts. It is not really matter if you experienced developer or not but including those two lines they will guide you in avoiding many many mistakes.

Having said that, sample of code included all the recommendations:

#!/usr/bin/perl use strict; use warnings; print "Please enter the first number: "; chomp (my $n1=<>); print "Please enter the second number: "; chomp (my $n2=<>); if ($n1 < $n2) { print "Output: $n1 $n2\n"; } else { print "Output: $n2 $n1\n"; } __END__ $ perl test.pl Please enter the first number: 4 Please enter the second number: 5 Output: 4 5
Update: Well I was bothered for a minute and I was thinking that your simple script will fail in case of non numerical characters. Your script can not handle this exception in case the user enters this type of characters as an input. So given this in consideration I used a simple perlre (read more on the link) and also a die function to capture this type of characters and exit in case that it matches.

Sample of code:

#!/usr/bin/perl use strict; use warnings; print "Please enter the first number: "; chomp (my $n1=<>); die "Please enter numerical(s) characters only not '$n1'!" unless $n1 =~ /^\d+$/; print "Please enter the second number: "; chomp (my $n2=<>); die "Please enter numerical(s) characters only not '$n2'!" unless $n2 =~ /^\d+$/; if ($n1 < $n2) { print "Output: $n1 $n2\n"; } else { print "Output: $n2 $n1\n"; } __END__ $ perl test.pl Please enter the first number: Test Please enter numerical(s) characters only not 'Test'! at test.pl line +8, <> line 1.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: outputs followed by each other by thanos1983
in thread outputs followed by each other by busyvish

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, details, 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, summary, 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.