As others have pointed out $a and $b have special meaning because they are used by sort.
After getting tripped up by this a few times, you will learn to use $x,$y or something else other than $a and $b!

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";

In reply to Re: I Keep getting the error: "my" variable $a masks earlier declaration in same scope at bigsmall.pl line 8 (#1) by Marshall
in thread I Keep getting the error: "my" variable $a masks earlier declaration in same scope at bigsmall.pl line 8 (#1) by sirpots

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.