in reply to Re: Matching part of a path
in thread Matching part of a path

Note how I used $path instead of your $a. This is for two reasons - first of all, $a and $b carry a special meaning for the sort function in Perl, so you shouldn't use them elsewhere. And secondly, $a is not very descriptive. Variables and functions should always have descriptive names, lest you find yourself boggling at your own code after putting it aside for two weeks.

Is this really true? You could use in sort $me and $my as well (any for that matter)? It should complain though if you are using scalars you've set up before (like doing double my).

Replies are listed 'Best First'.
Re^3: Matching part of a path
by Aristotle (Chancellor) on Dec 16, 2003 at 10:08 UTC
    Quoting perldoc -f sort:
    If the subroutine's prototype is ($$), the elements to be compared are passed by reference in @_, as for a normal subroutine. This is slower than unprototyped subroutines, where the elements to be compared are passed into the subroutine as the package global variables $a and $b (see example below). Note that in the latter case, it is usually counter-productive to declare $a and $b as lexicals.
    Perl only complains when you try to doubly declare a lexical variable name in the same scope. The following won't produce a complaint:
    use strict; use warnings; my $foo; { my $foo; }

    Makeshifts last the longest.