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
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.
In reply to Re: outputs followed by each other
by thanos1983
in thread outputs followed by each other
by busyvish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |