The two statements that delete leading and trailing spaces are Perl idioms. You will see them often. By convention, any leading or trailing spaces from user input should be ignored. "space characters", matching "\s" are: space,\n\r\t\f
Also in Perl, you do not need to use an intermediate variable to swap two variables this is re-ordering of a list.
Also, in Perl you can write the "if" at the end of the line if it is a "single action" if, a one statement if clause.
#!/usr/bin/perl use warnings; use strict; use diagnostics; print "Enter your First Number:\n"; my $first = <>; $first =~ s/^\s*//; #no leading spaces $first =~ s/\s*$//; #no trailing spaces (also "zapps" \n) print "Enter your Second Number:\n"; my $second = <>; $second =~ s/^\s*//; $second =~ s/\s*$//; ($first,$second) = ($second,$first) if $second < $first; print "The Biggest number is $second and the smallest number is $first +\n";
|
|---|