in reply to Sorting based on any column
>Trying to create a Subroutine to sort array based on any column numerically when my array is having both characters and numercis
I am not sure I completely understand the example...but this will sort alpha and numeric
#! /usr/local/bin/perl -w use strict; my $data = [qw| z x y 2 1 3 |]; print 'no sort:' , @$data ,"\n"; print 'sort: ' , (sort _sort_a_tron @$data) , "\n"; sub _sort_a_tron { no warnings; return ( $a <=> $b or $a cmp $b ); } # output # # no sort:zxy213 # sort: xyz123
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting based on any column
by Laurent_R (Canon) on May 19, 2015 at 22:33 UTC | |
by Anonymous Monk on May 20, 2015 at 11:07 UTC | |
by aaron_baugher (Curate) on May 20, 2015 at 11:25 UTC | |
by Anonymous Monk on May 21, 2015 at 12:46 UTC | |
by aaron_baugher (Curate) on May 21, 2015 at 13:39 UTC | |
| |
by aaron_baugher (Curate) on May 21, 2015 at 13:28 UTC | |
| |
by dasgar (Priest) on May 21, 2015 at 18:50 UTC | |
by Anonymous Monk on May 20, 2015 at 11:34 UTC | |
by Anonymous Monk on May 20, 2015 at 11:23 UTC |