Re: array sorting

2012-05-18 Thread Rob Dixon
On 17/05/2012 23:19, Shawn H Corey wrote: On 12-05-17 05:24 PM, Chris Stinemetz wrote: push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd); # push an anonymous array for each record push @fields, [ $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd ]; } } my @sorted_fields = sort { $a-[0]= $b-[0]

array sorting

2012-05-17 Thread Chris Stinemetz
I have an array @fields that contains 6 elements. I would like to sort the array by $fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in ascending order starting witht he first element before I print the array. I haven't been able to figure this out. Any help is greatly

Re: array sorting

2012-05-17 Thread Shawn H Corey
On 12-05-17 03:36 PM, Chris Stinemetz wrote: I would like to sort the array by $fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in ascending order starting witht he first element before I print the array. Do you want the fields sorted or do you want records sorted? If you want

Re: array sorting

2012-05-17 Thread Uri Guttman
On 05/17/2012 04:52 PM, Shawn H Corey wrote: On 12-05-17 03:36 PM, Chris Stinemetz wrote: I would like to sort the array by $fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in ascending order starting witht he first element before I print the array. Do you want the fields

Re: array sorting

2012-05-17 Thread Chris Stinemetz
Thank you Uri and Shawn. I am getting the following error and not sure how to resolve: I will also checkout the great suggestions Uri made. Can't use string (3) as an ARRAY ref while strict refs in use at ./DBSRtest.pl line 51, line 999. #!/usr/bin/perl use warnings; use strict; use POSIX;

Re: array sorting

2012-05-17 Thread Shawn H Corey
On 12-05-17 05:24 PM, Chris Stinemetz wrote: Thank you Uri and Shawn. I am getting the following error and not sure how to resolve: I will also checkout the great suggestions Uri made. Can't use string (3) as an ARRAY ref while strict refs in use at ./DBSRtest.pl line 51, line 999.

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-30 Thread newbie01 perl
Hi Rob, Thanks for your response and to everyone else who had given their thoughts, especially John. This whole exercise is turning out to be a fun way of learning arrays and print formatting. I tried the script that you suggested and it is giving some error and not sure how to get around it.

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-30 Thread Rob Dixon
On 30/10/2011 13:20, newbie01 perl wrote: Hi Rob, Thanks for your response and to everyone else who had given their thoughts, especially John. This whole exercise is turning out to be a fun way of learning arrays and print formatting. I tried the script that you suggested and it is giving some

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-25 Thread Rob Dixon
On 24/10/2011 21:35, John W. Krahn wrote: You forgot the part where the OP wants to sort the output. :-) I thought I didn't have enough information to know how the OP wanted the report sorted, but I see from the attacked shell script that the original lines from the df output are sorted before

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-24 Thread Rob Dixon
On 22/10/2011 03:18, newbie01 perl wrote: Hi all, Am trying to write/convert a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am using system(df -k /tmp/df_tmp.00); To re-direct the df output. Am using df -k because

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-24 Thread John W. Krahn
Rob Dixon wrote: **OUTPUT** FilesystemMBytes UsedAvail Capacity Mount -- - - - /dev/md/dsk/d1 3027-MB 2424-MB 542-MB 82% / /proc

Re: HELP on Perl array / sorting - trying to convert Korn ShellScript to Perl

2011-10-23 Thread Dr.Ruud
On 2011-10-22 17:37, timothy adigun wrote: my($filesys,$mbytes,$used,$avail,$capacity,$mount)=(,); Alternative: $_ = for my ( $p, $q, $r, $s ); -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread timothy adigun
Hi newbie01 perl, Try the code below and see if it works for you, it works well on my Ultimate Ubuntu OS. Assumptions in the code below: 1. you must pass df to the perl script on the Command Line Interface *e.g perl mydf.pl df*, 2. you don't have Perl6::Form installed, though you can get here

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread Brandon McCaig
On Sat, Oct 22, 2011 at 11:37 AM, timothy adigun 2teezp...@gmail.com wrote: my($filesys,$mbytes,$used,$avail,$capacity,$mount)=(,); Declaring these variables here is useless (and initializing them here is even more useless). :-/ The lack of whitespace is also useless and makes it more

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread Brandon McCaig
On Fri, Oct 21, 2011 at 10:18 PM, newbie01 perl newbie01.p...@gmail.com wrote: At the moment am using system(df -k /tmp/df_tmp.00); To re-direct the df output. Am using df -k because some of the Solaris and HP servers does not have df -h, by using df -k, am sure it will work on all of

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread Brandon McCaig
On Sat, Oct 22, 2011 at 3:00 PM, Brandon McCaig bamcc...@gmail.com wrote: http://search.cpan.org/~abarclay/Filesys-DiskFree-0.06/DiskFree.pm I guess the proper way to post a CPAN link is with the 'permalink': http://search.cpan.org/perldoc?Filesys::DiskFree Regards, -- Brandon McCaig

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread Brian Fraser
On Sat, Oct 22, 2011 at 4:57 PM, Brandon McCaig bamcc...@gmail.com wrote: On Sat, Oct 22, 2011 at 11:37 AM, timothy adigun 2teezp...@gmail.com wrote: my($filesys,$mbytes,$used,$avail,$capacity,$mount)=(,); Declaring these variables here is useless (and initializing them here is even

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread Brandon McCaig
On Sat, Oct 22, 2011 at 7:13 PM, Brian Fraser frase...@gmail.com wrote: I say this without a bit of sarcasm: Feel blessed in your ignorance of formats. The declarations on top are unfortunately needed (If it helps, think of formats using lexical variables as closures). But you shouldn't be

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-22 Thread GRAEME F ST CLAIR
Learning Perl turns out to be the 6th edition. Oh my! I thought to myself, perhaps mine might be about the 4th or 5th edition - alas, it is the 2nd. Start saving... Tx rgds, GFStC. On Fri, 21 Oct 2011 22:37:14 -0700 David Christensen dpchr...@holgerdanske.com wrote: The canonical

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-21 Thread newbie01 perl
Hi all, Am trying to write/convert a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am using system(df -k /tmp/df_tmp.00); To re-direct the df output. Am using df -k because some of the Solaris and HP servers does not have df -h,

Re: HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

2011-10-21 Thread David Christensen
On 10/21/2011 07:18 PM, newbie01 perl wrote: Am trying to write/convert a customized df script... I've attached a version of the script in Korn shell. ... ... [input] Filesystemkbytesused avail capacity Mounted on /dev/md/dsk/d1 3099287 2482045 55525782%/

more hashref within array sorting

2005-08-09 Thread Jeremy Kister
I've got an array full of hashrefs: my @a = ( {N = '10.1.2.1'}, {N = '10.1.9.1'}, {N = '10.3.5.1'}, {N = '10.1.1.3'}, ); I want to sort this array, and print. I expect the output resemble: 10.1.1.3 10.1.2.1 10.1.9.1 10.3.5.1 I've fumbled with this for a

Re: more hashref within array sorting

2005-08-09 Thread Paul Johnson
On Tue, Aug 09, 2005 at 06:03:18AM -0400, Jeremy Kister wrote: I've got an array full of hashrefs: my @a = ( {N = '10.1.2.1'}, {N = '10.1.9.1'}, {N = '10.3.5.1'}, {N = '10.1.1.3'}, ); I want to sort this array, and print. I expect the output

Re: more hashref within array sorting

2005-08-09 Thread Jeremy Kister
On 8/9/2005 6:26 AM, Paul Johnson wrote: my @s = map { $_ - [0] } sort { $a-[0] = $b-[0] || $a-[1] = $b-[1] || $a-[2] = $b-[2] || $a-[3] = $b-[3] } map { [ $_, split /\./ ] } map { $_-{N} } @a; You clearly solved the

Re: more hashref within array sorting

2005-08-09 Thread Paul Johnson
On Tue, Aug 09, 2005 at 06:53:33AM -0400, Jeremy Kister wrote: On 8/9/2005 6:26 AM, Paul Johnson wrote: my @s = map { $_ - [0] } sort { $a-[0] = $b-[0] || $a-[1] = $b-[1] || $a-[2] = $b-[2] || $a-[3] = $b-[3] } map { [

Re: more hashref within array sorting

2005-08-09 Thread John W. Krahn
Jeremy Kister wrote: On 8/9/2005 6:26 AM, Paul Johnson wrote: my @s = map { $_ - [0] } sort { $a-[0] = $b-[0] || $a-[1] = $b-[1] || $a-[2] = $b-[2] || $a-[3] = $b-[3] } map { [ $_, split /\./ ] } map { $_-{N} } @a; You

Re: more hashref within array sorting

2005-08-09 Thread Jeremy Kister
On 8/9/2005 8:43 AM, John W. Krahn wrote: Jeremy Kister wrote: I've apparently dumbed down my code and question a bit too much: I have multiple hashrefs in each element of the array, and I need the resulting sorted array to contain all the data in the original array, simply sorted by the value

Re: more hashref within array sorting

2005-08-09 Thread Jeff 'japhy' Pinyan
On Aug 9, Jeremy Kister said: my @s = map $_-[ 1 ], sort { $a-[ 0 ] cmp $b-[ 0 ] } map [ inet_aton( $_-{ N } ), $_ ], @a; Now to analyze WTF we're doing here :) Paul's answer had a slight typo in it -- he was comparing $a-[0], $a-[1], $a-[2], and $a-[3], when he

Re: more hashref within array sorting

2005-08-09 Thread Paul Johnson
On Tue, Aug 09, 2005 at 05:00:44PM -0400, Jeff 'japhy' Pinyan wrote: On Aug 9, Jeremy Kister said: my @s = map $_-[ 1 ], sort { $a-[ 0 ] cmp $b-[ 0 ] } map [ inet_aton( $_-{ N } ), $_ ], @a; Now to analyze WTF we're doing here :) Paul's answer had a slight

hash array sorting

2005-06-03 Thread Mike Blezien
Hello, ran into a strange problem when doing a sort. we have a file like this: 0::Accounts;Local Language 1::Anatomy;Local Language 2::Arabic;Local Language .. 26::German;Local Language 27::Governmentpolitics;Local Language . 3::Architecture;Local Language

Re: hash array sorting

2005-06-03 Thread Sean Davis
Look at using lc (lower case). It can make your sort case-insensitive. On Jun 3, 2005, at 7:17 PM, Mike Blezien wrote: Hello, ran into a strange problem when doing a sort. we have a file like this: 0::Accounts;Local Language 1::Anatomy;Local Language 2::Arabic;Local Language

Re: hash array sorting

2005-06-03 Thread Mike Blezien
How that apply to our code: foreach $key (sort { $lang-{$a}-[0] cmp $lang-{$b}-[0] } keys(%{$lang})) { # do stuff here } Sean Davis wrote: Look at using lc (lower case). It can make your sort case-insensitive. On Jun 3, 2005, at 7:17 PM, Mike Blezien wrote: Hello, ran into

Array sorting.

2003-04-12 Thread Chris
Hi Guys, I have something im basically stumped on, so mabey somebody can give me a hand ;) This is my scenario: I have a bunch of random URL's in a plain text file. I also have a text file with just the domain of certain URL's that are in the random URL file. IE: random file:

Re: Array sorting.

2003-04-12 Thread Wiggins d'Anconia
Chris wrote: Hi Guys, I have something im basically stumped on, so mabey somebody can give me a hand ;) This is my scenario: I have a bunch of random URL's in a plain text file. I also have a text file with just the domain of certain URL's that are in the random URL file. IE: random

Re: Array sorting (yet another trains question)

2003-03-30 Thread Peter Scott
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Rob Richardson) writes: --- Peter Scott [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Rob Richardson) writes: sub GetTrainsByTime { my $self = shift; my @result; my @temp; my $aTrain; my

Array sorting (yet another trains question)

2003-03-29 Thread Rob Richardson
Greetings! In the train schedule program that you are all probably heartily sick of by now, I have added a ScheduleDay class that represents all trains running on a given day. It has a method that returns an array of references to all of the Train objects for that day. I want to sort those

Re: Array sorting (yet another trains question)

2003-03-29 Thread Peter Scott
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Rob Richardson) writes: Greetings! In the train schedule program that you are all probably heartily sick of by now, I have added a ScheduleDay class that represents all trains running on a given day. It has a method that returns an array of

Re: Array sorting (yet another trains question)

2003-03-29 Thread Rob Richardson
Peter, Thanks for your reply. My responses are in-line below. Rob --- Peter Scott [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Rob Richardson) writes: sub GetTrainsByTime { my $self = shift; my @result; my @temp; my $aTrain; my

Re: Array sorting (yet another trains question)

2003-03-29 Thread Wiggins d'Anconia
Rob Richardson wrote: (1) If you wanted to put the keys of a hash into an array, just do it all at once: @temp = keys %$self I am not putting the keys of the hash into the temporary array. I'm putting the values of the hash into the array. In that case, perldoc -f values, 'values' does the