in reply to Re^3: Prototype like sort()?
in thread Prototype like sort()?
While I would not recommend it, $a and $b are only special in that they are predeclared and used by sort. Otherwise, you can use them like any other package variable:
sub mysort (&@) { my $coderef = shift; while (@_ > 1) { $a = shift; $b = $_[0]; my $c = $coderef->(); print " $c"; # do sorting } print "\n"; } mysort { $a <=> $b } qw(1 3 2);
But, it is a bad idea to use $a and $b except with sort
But, could use 2 other variables. Just have to declare them.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Prototype like sort()?
by Laurent_R (Canon) on Jan 28, 2018 at 00:09 UTC |