in reply to Using $a and $b for sort

The short answer: don't use $a and $b for anything except sorting and the like.

They are an exception in that they are not subject to use strict;, so it's best to avoid them.

Replies are listed 'Best First'.
Re^2: Using $a and $b for sort
by Antony Lewis (Initiate) on Jan 04, 2008 at 03:45 UTC
    Thanks for the response, That makes sense... I did that, but what in case if you want to change these default variables??? Any clue???
      if there is some strange reason you cannot lexify your other usages of $a and $b, then you can consider using a named ($$)-prototyped sort subroutine, and perl will pass the sort variables in @_ instead of package variables.
      sub mysort ($$) { $_[0]->{key} <=> $_[1]->{key} } my @sorted = sort mysort @unsorted;