Ask a Question related to PERL Miscellaneous, Design and Development.
-
Bogdan #1
sort issue
Hi there,
I need to sort elements of of list/array by character. For instance I
got "hdisk1 hdisk10 hdisk11 hdisk2 hdisk3 ... " and need to have
"hdisk1 hdisk2 hdisk3 ... hdisk10 hdisk11 ..."
I can do that using external programs like
$ cat file_with_hdisks | sort -n -k1.6
but I'd like to do it in perl. Does anyone have any piece of code or
at least idea how to achieve that in as easy way as passible?
Thanks,
Bogdan
Bogdan Guest
-
Sort a ds
Hello, I need to sort a ds. I did this via a view and now I want to send the view back to the ds. How can I do that? Thanks -
datagrid sort issue
Hello group, The webpage I am working with has 3 datagrids. All the 3 datagrids pretty much does the same thing expect for some minor variations.... -
A sort of IF THEN ELSE in SQL
Hi All I know this isn't an SQL syntax NG per say (esp MySQL), but there are far more legible gurus in here than the MySQL groups so I hope you... -
memory sort and disk sort
I check the sysprofile table and find there are 700 times disk sort, I think it is lack of sort memory. I want to turn all the disk sort into the... -
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB.
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp... -
Matija Papec #2
Re: sort issue
X-Ftn-To: Bogdan
[email]bogdan_czyz@hotmail.com[/email] (Bogdan) wrote:[url]http://www.google.com/search?q=schwartzian[/url]>Hi there,
>I need to sort elements of of list/array by character. For instance I
>got "hdisk1 hdisk10 hdisk11 hdisk2 hdisk3 ... " and need to have
>"hdisk1 hdisk2 hdisk3 ... hdisk10 hdisk11 ..."
>I can do that using external programs like
>$ cat file_with_hdisks | sort -n -k1.6
>
>but I'd like to do it in perl. Does anyone have any piece of code or
>at least idea how to achieve that in as easy way as passible?
#untested
my @arr = qw/hdisk1 hdisk10 hdisk11 hdisk2 hdisk3/;
@arr =
map $_->[0],
sort {
$a->[1] cmp $b->[1] ||
$a->[2] <=> $b->[2]
}
map [ $_, /(\w+)(\d+)/ ], @arr;
--
Matija
Matija Papec Guest
-
Tad McClellan #3
Re: sort issue
Bogdan <bogdan_czyz@hotmail.com> wrote:
^^^^^^^^^^> I need to sort elements of of list/array by character. For instance I> got "hdisk1 hdisk10 hdisk11 hdisk2 hdisk3 ... "
That is not a "list/array", that is a string.
> and need to have
> "hdisk1 hdisk2 hdisk3 ... hdisk10 hdisk11 ..."
There are several Frequently Asked Questions about sorting,
have you already seen their answers?
> I can do that using external programs like
> $ cat file_with_hdisks | sort -n -k1.6
Why are you stopping at the 6th character when some of your pieces
have 7 characters? (eg. hdisk10).
You have a Useless Use Of Cat as well:
sort -n -k1.6 file_with_hdisks
> but I'd like to do it in perl. Does anyone have any piece of code or
> at least idea how to achieve that in as easy way as passible?
---------------------------
#!/usr/bin/perl
use strict;
use warnings;
my @parts = split /\s+/, 'hdisk1 hdisk10 hdisk11 hdisk2 hdisk3';
print "$_\n" for @parts; # before
print "----\n";
@parts = sort { substr($a, 5) <=> substr($b, 5) } @parts;
print "$_\n" for @parts; # after
---------------------------
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-



Reply With Quote

