Re: hash of arrays sorting

2012-08-23 Thread Salvador Fandino
> IIRC, a long time ago I send you a patch for Sort::Maker benchmarking > script incorporating Sort::Key variants that showed how faster my module > can be. I would try to find it and send it to you again. Well, I have been unable to find it... but I have redone it :-) Attached are the patch tha

Re: hash of arrays sorting

2012-08-23 Thread Salvador Fandino
On 08/23/2012 09:10 AM, Uri Guttman wrote: > On 08/23/2012 02:54 AM, Salvador Fandino wrote: > >>> >>> It's a pity Sort::Maker not in Debian >> >> There is also Sort::Key, available in Debian testing and unstable, and >> which is usually faster than Sort::Maker and also Sort::Key::Radix, even >> f

Re: hash of arrays sorting

2012-08-23 Thread Rob Coops
On Thu, Aug 23, 2012 at 9:10 AM, Uri Guttman wrote: > On 08/23/2012 02:54 AM, Salvador Fandino wrote: > > >>> It's a pity Sort::Maker not in Debian >>> >> >> There is also Sort::Key, available in Debian testing and unstable, and >> which is usually faster than Sort::Maker and also Sort::Key::Radi

Re: hash of arrays sorting

2012-08-23 Thread Uri Guttman
On 08/23/2012 02:54 AM, Salvador Fandino wrote: It's a pity Sort::Maker not in Debian There is also Sort::Key, available in Debian testing and unstable, and which is usually faster than Sort::Maker and also Sort::Key::Radix, even faster when sorting by numeric keys but not available in Debian

Re: hash of arrays sorting

2012-08-22 Thread Salvador Fandino
On 08/22/2012 10:34 PM, Eduardo wrote: > On 22/08/12 03:49, Uri Guttman wrote: >> On 08/21/2012 08:29 PM, Eduardo wrote: >>> how would you do with Sort::Maker? >> i don't have time to show an example now but it is much cleaner >> looking. all you need to do is code up how you extract each key from

Re: hash of arrays sorting

2012-08-22 Thread Eduardo
On 22/08/12 03:49, Uri Guttman wrote: > On 08/21/2012 08:29 PM, Eduardo wrote: >> how would you do with Sort::Maker? > i don't have time to show an example now but it is much cleaner > looking. all you need to do is code up how you extract each key from > the data set and how it gets sorted (number

Re: hash of arrays sorting

2012-08-21 Thread Uri Guttman
On 08/21/2012 08:29 PM, Eduardo wrote: On 22/08/12 00:35, Uri Guttman wrote: my %cache = (); foreach ( keys %$hash ) { my ( $naa, $nab ) = $_ =~ m|^(\d+)-(\d+)|; $cache{ ($naa * 100 + $nab ) } = $_; } that is a variant of the orcish manoever which is supported by sort::maker. fore

Re: hash of arrays sorting

2012-08-21 Thread Eduardo
On 22/08/12 00:35, Uri Guttman wrote: > On 08/21/2012 05:33 PM, Eduardo wrote: >> On 21/08/12 22:05, Chris Stinemetz wrote: >>> Hello List, >>> >>> I am trying to sort a hash of arrays ( example below: ) >>> >>> I would the sort to sort in ascending order the first index of the >>> array >>> then

Re: hash of arrays sorting

2012-08-21 Thread Uri Guttman
On 08/21/2012 05:33 PM, Eduardo wrote: On 21/08/12 22:05, Chris Stinemetz wrote: Hello List, I am trying to sort a hash of arrays ( example below: ) I would the sort to sort in ascending order the first index of the array then the second index of the array. So in this example the arrays wou

Re: hash of arrays sorting

2012-08-21 Thread Eduardo
On 21/08/12 22:05, Chris Stinemetz wrote: > Hello List, > > I am trying to sort a hash of arrays ( example below: ) > > I would the sort to sort in ascending order the first index of the array > then the second index of the array. > > So in this example the arrays would sort to: > > 97,2,120,65 >

Re: hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
I will leave it to you to write an actual program incorporating these > ideas. > > Thank you Jim for the excelent explanation. This seems to do the trick. foreach my $cellNo ( sort { $hash{$a}->[0] <=> $hash{$b}->[0] || $hash{$a}->[1] <=> $hash{$b}->[1] } keys %hash ) { print join( "\0", @{

Re: hash of arrays sorting

2012-08-21 Thread Jim Gibson
On Aug 21, 2012, at 1:23 PM, Jim Gibson wrote: > > On Aug 21, 2012, at 1:05 PM, Chris Stinemetz wrote: > >> Hello List, >> >> I am trying to sort a hash of arrays ( example below: ) >> >> I would the sort to sort in ascending order the first index of the array >> then the second index of the

Re: hash of arrays sorting

2012-08-21 Thread Jim Gibson
On Aug 21, 2012, at 1:05 PM, Chris Stinemetz wrote: > Hello List, > > I am trying to sort a hash of arrays ( example below: ) > > I would the sort to sort in ascending order the first index of the array > then the second index of the array. I believe you mean "first element" rather than "first

Re: hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
On Tue, Aug 21, 2012 at 3:11 PM, Shawn H Corey wrote: > On Tue, 21 Aug 2012 15:05:33 -0500 > Chris Stinemetz wrote: > > > I am trying to sort a hash of arrays ( example below: ) > > > > I would the sort to sort in ascending order the first index of the > > array then the second index of the array

Re: hash of arrays sorting

2012-08-21 Thread Shawn H Corey
On Tue, 21 Aug 2012 15:05:33 -0500 Chris Stinemetz wrote: > I am trying to sort a hash of arrays ( example below: ) > > I would the sort to sort in ascending order the first index of the > array then the second index of the array. What have you tried so far? Can we see the code? -- Just my 0

Re: hash of arrays question

2011-11-17 Thread Rob Dixon
On 17/11/2011 07:56, Stefan Wiederoder wrote: Hello Brandon, thanks a lot for your help - your code works like a charm, I´ve already put in my script which is now generating puppet node/classes definitions. Sometimes, but very rarely, the answer to a question should include working code. It i

Re: hash of arrays question

2011-11-17 Thread Stefan Wiederoder
Hello Brandon, thanks a lot for your help - your code works like a charm, I´ve already put in my script which is now generating puppet node/classes definitions. bye , Stefan -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http:/

Re: hash of arrays question

2011-11-16 Thread John SJ Anderson
On Tuesday, November 15, 2011 at 11:10 , Stefan Wiederoder wrote: > Hello list, > > I´m using a json config file to read a file with server group > definitions, including group of groups like > this example: > > [jdoe@belbo]# cat groups.json > { > "G_Group_PR" : [ "serverA", "serverB" ], > "G_G

Re: hash of arrays question

2011-11-15 Thread Jim Gibson
On 11/15/11 Tue Nov 15, 2011 8:10 AM, "Stefan Wiederoder" scribbled: > Hello list, > > I´m using a json config file to read a file with server group > definitions, including group of groups like > this example: > > [jdoe@belbo]# cat groups.json > { > "G_Group_PR" : [ "serverA", "serve

Re: hash of arrays question

2011-11-15 Thread Brandon McCaig
Hello Stefan, On Tue, Nov 15, 2011 at 08:10:12AM -0800, Stefan Wiederoder wrote: > Hello list, > > I´m using a json config file to read a file with server group > definitions, including group of groups like > this example: > > [jdoe@belbo]# cat groups.json > { > "G_Group_PR" : [ "serverA

Re: hash of Arrays

2010-01-18 Thread Chris Charley
- Original Message - From: ""Johnson, Reginald (GTS)"" Newsgroups: perl.beginners To: Sent: Sunday, January 17, 2010 2:42 PM Subject: hash of Arrays I am trying to place the date of each day of the week for each month that has 5 weeks into a hash. For instance my hash key 'Monday' w

Re: hash of Arrays

2010-01-18 Thread Dermot
2010/1/17 Johnson, Reginald (GTS) : > I am trying to place the date of each day of the week for each month > that has 5 weeks into a hash. For instance my hash key 'Monday' would > point to an array that has all the dates where Monday is in the fifth > week of the month. > I've got that part going.

Re: hash of Arrays

2010-01-18 Thread Shlomi Fish
Hi Reginald! On Sunday 17 Jan 2010 21:42:21 Johnson, Reginald (GTS) wrote: > I am trying to place the date of each day of the week for each month > that has 5 weeks into a hash. For instance my hash key 'Monday' would > point to an array that has all the dates where Monday is in the fifth > week o

Re: hash of arrays

2008-08-19 Thread Dr.Ruud
"Dr.Ruud" schreef: > "ANJAN PURKAYASTHA": >> $HOA{$key}= [qw(a,b,c,d)]; > > which is equivalent to > > $HOA{ $key } = [ 'a', 'b', 'c', 'd' ]; Oops, as Ron wrote, your qw(a,b,c,d) was probably meant to be qw(a b c d). -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAI

Re: hash of arrays

2008-08-19 Thread Ron Bergin
On Aug 18, 1:03 pm, [EMAIL PROTECTED] (Anjan Purkayastha) wrote: > hi, > i'm struggling with a hash of arrays problem. > suppose i create the following HOA: > $HOA{$key}= [qw(a,b,c,d)]; I doubt that the results of that assignment is what you want/expect. #!/usr/bin/perl #use strict; use warnings

Re: hash of arrays

2008-08-18 Thread Dr.Ruud
"ANJAN PURKAYASTHA" schreef: > i'm struggling with a hash of arrays problem. > suppose i create the following HOA: > $HOA{$key}= [qw(a,b,c,d)]; which is equivalent to $HOA{ $key } = [ 'a', 'b', 'c', 'd' ]; and can also be written as $HOA{ $key } = [ 'a' .. 'd' ]; > how do i push an eleme

Re: hash of arrays

2008-08-18 Thread Mr. Shawn H. Corey
On Mon, 2008-08-18 at 16:03 -0400, ANJAN PURKAYASTHA wrote: > hi, > i'm struggling with a hash of arrays problem. > suppose i create the following HOA: > $HOA{$key}= [qw(a,b,c,d)]; > > how do i push an element into the $HOA{$key} array? > > tia, > anjan > By de-referencing it: push @{ $HOA{

RE: Hash of Arrays

2005-09-23 Thread Jim
> > The part that confuses me is: > > ($who, $rest) = split /:\s*/, $line, 2; > > I understand that it takes the input and splits it into two > parts along the regular expression, but I can't figure out > what the 2 means. > split the expression into a maximum of 2 perldoc -f split --

RE: Hash of Arrays

2005-09-20 Thread Timothy Johnson
Matija Papec wrote: > > Christopher Spears wrote: >> while ($line = <>) { >> ($who, $rest) = split /:\s*/, $line, 2; >> @fields = split ' ', $rest; >> $HoA{$who} = [ @fields ]; >> } >> >> The part that confuses me is: >> >> ($who, $rest) = split /:\s*/, $line, 2; >> >> I understand t

Re: Hash of Arrays

2005-09-20 Thread Matija Papec
Christopher Spears wrote: while ($line = <>) { ($who, $rest) = split /:\s*/, $line, 2; @fields = split ' ', $rest; $HoA{$who} = [ @fields ]; } The part that confuses me is: ($who, $rest) = split /:\s*/, $line, 2; I understand that it takes the input and splits it into two parts alo

Re: Hash of Arrays

2005-09-20 Thread Prasanna Kothari
Hi. From documentation: perldoc -f split split /PATTERN/,EXPR,LIMIT If LIMIT is specified and positive, splits into no more than that many fields (though it may split into fewer). If LIMIT is unspecified or zero, trailing null fields are stripped. If LIMIT is negative, it is treated as if an ar

Re: Hash of Arrays

2005-09-20 Thread Ankur Gupta
On 9/20/2005 11:16 PM Christopher Spears wrote: I've been learning about data structures by reading the Programming Perl book. Here is a code snippet: while ($line = <>) { # If $line = "abcd: efgh: ijkl"; ($who, $rest) = split /:\s*/, $line, 2; # then $who = "abcd" and $rest = "efgh:

Re: Hash of Arrays, p. 276

2005-05-28 Thread Peter Rabbitson
> Please look at the definition and initialization of the hash. It is a hash > of array references, isn't it? Why does > $HoA{"flintstone"}[0] work, why is not it: $HoA{"flintstone"}->[0] > perldoc perlref Section: Using References Paragraph 3 $array[$x]->{"foo"}->[0]

RE: [ Hash of Arrays]

2004-05-05 Thread Tim Johnson
:[EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 5:36 AM To: [EMAIL PROTECTED] Subject: Re: [ Hash of Arrays] If you want it to be a hash ref you need my $ModelPath = { ... }; and if you want it to be a hash you'd need to use () instead of {}

Re: [ Hash of Arrays]

2004-05-05 Thread JupiterHost.Net
[EMAIL PROTECTED] wrote: No, I want to use Hash of Arrays. I want to define the hash in a better manner say something similar to the following way. my %ModelPath = { "2800" => [EMAIL PROTECTED], "4345" => [EMAIL PROTECTED] }

RE: [ Hash of Arrays]

2004-05-04 Thread suresh.pasupula
}; But by doing so I am not getting the values for the respective keys. -Original Message- From: Tim Johnson [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 11:01 AM To: Suresh Pasupula (WT01 - EMBEDDED & PRODUCT ENGINEERING SOLUTIONS); [EMAIL PROTECTED] Subject: RE: [ Hash

RE: [ Hash of Arrays]

2004-05-04 Thread Tim Johnson
Oops! That last line should be: my @tempArray = @{$_}; -Original Message- From: Tim Johnson Sent: Tuesday, May 04, 2004 10:36 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: [ Hash of Arrays] I think you might actually want an array of arrays (list of lists, etc

RE: [ Hash of Arrays]

2004-05-04 Thread Tim Johnson
@{$temp}; } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 04, 2004 10:22 PM To: [EMAIL PROTECTED] Subject: RE: [ Hash of Arrays] --- Also is there a better way to define a hash when I already have existing arrays rather than defining

RE: [ Hash of Arrays]

2004-05-04 Thread Tim Johnson
First I'll show you ONE of the right ways: use strict; use warnings; #declare the arrays my @one = ("abc", "def"); my @two = ("ABC", "DEF"); #initialize the hash (note the parens) my %ModelPath = (); #add the arrays to the hash $ModelPath{1} = [EMAIL PROTECTED];

RE: [ Hash of Arrays]

2004-05-04 Thread suresh.pasupula
2004 10:37 AM To: Suresh Pasupula (WT01 - EMBEDDED & PRODUCT ENGINEERING SOLUTIONS) Subject: RE: [ Hash of Arrays] Hey Suresh, Try something like this: my @one = ("abc", "def"); my @two = ("ABC", "DEF"); my %ModelPath = {}; $ModelPath{"1"}

Re: hash of arrays

2003-09-11 Thread Phillip E. Thomas
Dereferencing the array was exactly what I wanted. Thank you! "James Edward Gray II" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > On Thursday, September 11, 2003, at 06:58 AM, Phillip E. Thomas wrote: > > > my %hash=(); > > my $mykey="key"; > > my $myval1=$myval2="test"; > > >

RE: hash of arrays

2003-09-11 Thread Dan Muey
> my %hash=(); > my $mykey="key"; > my $myval1=$myval2="test"; > > #store data in a hash of arrays > $hash{$mykey}=[$myval1, $myval2]; > > Later on I want to retrieve the data and I have to do it like: > > $myval1=$hash{$mykey}[0]; > $myval2=$hash{$mykey}[1]; > > There are a lot of array values

Re: hash of arrays

2003-09-11 Thread James Edward Gray II
On Thursday, September 11, 2003, at 06:58 AM, Phillip E. Thomas wrote: my %hash=(); my $mykey="key"; my $myval1=$myval2="test"; #store data in a hash of arrays $hash{$mykey}=[$myval1, $myval2]; Later on I want to retrieve the data and I have to do it like: $myval1=$hash{$mykey}[0]; $myval2=$hash

Re: hash of arrays

2003-01-12 Thread John W. Krahn
Nicole Seitz wrote: > > hi there! Hello, > I've got a problem with a complex data structure and hope you can help me. > > I know that I can't have a hash whose values are arrays. So I tried to > build a hash of references to arrays. > > I guess I've made some mistakes . > > This is what my

Re: hash of arrays

2003-01-12 Thread Rob Dixon
Hi Nicole "Nicole Seitz" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > hi there! > > I've got a problem with a complex data structure and hope you can help me. > > I know that I can't have a hash whose values are arrays. So I tried to > build a hash of refer

RE: hash of arrays

2003-01-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Nicole Seitz wrote: > hi there! > > I've got a problem with a complex data structure and hope you can > help me. > > I know that I can't have a hash whose values are arrays. So I tried > to build a hash of references to arrays. > > I guess I've made some mistakes . > > This is what my hash

Re: Hash of arrays

2001-07-25 Thread Troy Denkinger
On Wednesday 25 July 2001 10:26, Diego Riaño wrote: > I want to retrieve the name of one of the original arrays, for example > retrieve: > > @NumericalResults > to use it in another function. Hmmm, I'm not sure what you're getting at here. You've create a hash or arrays, why not just pass a ref

Re: Hash of arrays

2001-06-28 Thread Brett W. McCoy
On Thu, 28 Jun 2001, F.H wrote: > I just wonder why the if condition is always true regardless of the value of the >array AB. > @AB = [1,2], and $i gets printed even for values not inlcuded in array AB. > > foreach $i ( 0 .. $#{ $testsec{'AB'} } ) { > if ($testsec{'AB'}[$i] = "6543")

RE: Hash of arrays

2001-06-28 Thread mark crowe (JIC)
You've got caught in the old = vs == trap. A single = sign sets the variable on the left to equal that on the right, while == tests for equality. So in your case $testsec{'AB'}[$i] = "6543" sets $testsec{'AB'}[$i] to "6543", and then returns 'true' (yes, I have successfully set that var

Re: Hash of arrays

2001-06-28 Thread Paul
--- Paul <[EMAIL PROTECTED]> wrote: > > --- "F.H" <[EMAIL PROTECTED]> wrote: > > I just wonder why the if condition is always true regardless of the > > value of the array AB. > > if ($testsec{'AB'}[$i] = "6543"){ # always true > > Because = is an assignment. =o) > > print "fo

Re: Hash of arrays

2001-06-28 Thread Paul
--- "F.H" <[EMAIL PROTECTED]> wrote: > I just wonder why the if condition is always true regardless of the > value of the array AB. > if ($testsec{'AB'}[$i] = "6543"){ # always true Because = is an assignment. =o) print "foo" if $x = "65343"; will always print, because = retu

Re: Hash of arrays.......stuck!!

2001-06-27 Thread Me
($title, $rest) = split ' ', $_, 2; @fields = split ' ',$rest; last two lines === ($title, @fields) = split ' '; which is almost ($title, @fields) = split; foreach $keytitle (keys %TITLES) { if ( grep /$keytitle/, $lookup ) { $lookup is an arr

Re: Hash of Arrays Question

2001-05-01 Thread Paul
--- "J. Patrick Lanigan" <[EMAIL PROTECTED]> wrote: > I haven't quite sorted out the more complex data structure in perl > yet. Anyhow, I need to take the following hash of arrays... > > my %tracks = (); > > push @{$tracks{$filename}}, > $_, # tracks.fi

RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan
Thank you so much for your help Gary and Jason. I tried the following and it works perfectly. Patrick #!c:/perl/bin/perl -w use strict; my %tracks=(); # create empty hash $tracks{'test'}->{artist}='test_artist'; $tracks{'test'}->{title}='test_title'; $tracks{'test2'}->{artist}='test_artist2'; $

RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan
Opps, forgot to change the variable name. Ah the power of cut and paste... for my $row ( keys %tracks ) { $artist = $tracks{$row}->{artist}; $title = $tracks{$row}->{title}; } > I wrote: > > Excellent! Thanks! So, when I need to iterate through the hash of > hashes and > wor

RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan
Excellent! Thanks! So, when I need to iterate through the hash of hashes and work on the data would I do this: for my $row ( keys %tracks ) { $artist = $tracks{$fname}->{artist}; $title = $tracks{$fname}->{title}; } Thanks again for the pointer, Patrick > Gary Stainburn wrote:

Re: Hash of Arrays Question

2001-05-01 Thread Gary Stainburn
Surely, a hash of hashes would be better then. my %tracks=(); # create empty hash Then to populate the data you do something like: $tracks{$fname}->{artist}=$artist; $tracls{$fname}->{title}=$title; Gary On Tuesday 01 May 2001 4:08 pm, J. Patrick Lanigan wrote: > Overall what I am trying to

RE: Hash of Arrays Question

2001-05-01 Thread J. Patrick Lanigan
Overall what I am trying to accomplish is to loop through a bunch of mp3 files and extract the ID3 Tag Info into a hash (%tracks) for which each key references the filename, filepath, artist, album, tracknum, title, genre for one file. Once I have %tracks populated I need to iterate through it and

RE: Hash of Arrays Question

2001-05-01 Thread King, Jason
J. Patrick Lanigan writes .. >I haven't quite sorted out the more complex data structure in perl yet. >Anyhow, I need to take the following hash of arrays... you have some very confusing code there .. so let's do it one bit at a time >my %tracks = (); create a hash called tracks with zero e