in reply to Accessing $a and $b of 'sort' across package boundaries
Use the alternate usage of sort:
foreach ( sort gs::long_strings_first @$raw_hash_keys_ar ) { #do_stuff; } package gs; sub long_strings_first($$) { return 0 unless defined $_[0]; return 0 unless defined $_[1]; length $_[1] <=> length $_[0] || lc $_[1] cmp lc $_[0] }
Why did you check if $b is undefined and not $a? If there can be undefined values in the list to be sorted, both $a and $b could be undefined. I added the extra check.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Accessing $a and $b of 'sort' across package boundaries
by davidrw (Prior) on Jun 06, 2005 at 19:26 UTC | |
by ikegami (Patriarch) on Jun 06, 2005 at 19:34 UTC | |
by davidrw (Prior) on Jun 06, 2005 at 19:49 UTC | |
by ikegami (Patriarch) on Jun 06, 2005 at 20:54 UTC | |
|
Re^2: Accessing $a and $b of 'sort' across package boundaries
by ff (Hermit) on Jun 06, 2005 at 19:28 UTC |