RE: Creating a hash of arrays from

2014-07-10 Thread Sunita Pradhan
}; I guess you want output something like this . > From: p...@surfshopcart.com > Subject: Creating a hash of arrays from > Date: Wed, 9 Jul 2014 18:59:58 -0700 > To: beginners@perl.org > > I'm having a problem creating a hash of arrays. The while loop below > works,

Re: Creating a hash of arrays from

2014-07-10 Thread SSC_perl
On Jul 10, 2014, at 9:00 AM, Ron Bergin wrote: > my($state, @zipcodes) = split /[=,]/, $line; Interesting concept, the multiple split. I'd be interested in knowing how Perl knows to give the singular value on the left of the "=" to $state and all other values split on the "," to @zipcod

Re: Creating a hash of arrays from

2014-07-10 Thread Ron Bergin
Ron Bergin wrote: > Others have already pointed what you were doing wrong, so I'll point out > something else. > > Instead of using 2 separate split statements, I'd use a single split > statement to assign $state and a @zipcodes array. > > use 5.010; > use strict; > use warnings; > use Data::Dumpe

Re: Creating a hash of arrays from

2014-07-10 Thread Ron Bergin
SSC_perl wrote: > If someone could explain what I'm doing wrong, I'd appreciate it. I > just > can't see it. > > Thanks, > Frank > > -- > > use strict; > use warnings; > use 5.010; > > use Data::Dumper; > > my %entries; > > while (my $line = ) { > chomp $line;

Re: Creating a hash of arrays from

2014-07-10 Thread Nathan Hilterbrand
Hi Frank On 07/10/2014 11:02 AM, SSC_perl wrote: On Jul 10, 2014, at 7:14 AM, Nathan Hilterbrand wrote: $entries{$state} = [ (split /,/ => $zipcodes) ]; Thanks, Nathan. The line above caught my eye. It's interesting to see that you don't need both 'push' and 'split' to populate th

Re: Creating a hash of arrays from

2014-07-10 Thread SSC_perl
On Jul 10, 2014, at 7:14 AM, Nathan Hilterbrand wrote: > $entries{$state} = [ (split /,/ => $zipcodes) ]; Thanks, Nathan. The line above caught my eye. It's interesting to see that you don't need both 'push' and 'split' to populate the hash. Could you explain a little about wh

Re: Creating a hash of arrays from

2014-07-09 Thread SSC_perl
On Jul 9, 2014, at 7:56 PM, John SJ Anderson wrote: > This foreach loop is looping over the five zip codes in the array... > >> print Dumper (@{$entries{$state}}); > > And printing out the same array each time. Thanks, John. I wasn't even looking at the printout loop. :\ For so

Re: Creating a hash of arrays from

2014-07-09 Thread John SJ Anderson
On Wed, Jul 9, 2014 at 6:59 PM, SSC_perl wrote: > If someone could explain what I'm doing wrong, I'd appreciate it. I > just can't see it. You're looping over the entries in the array, not the entries in the hash. > foreach my $state (sort keys %entries) { > say "The Zip Codes of $

Creating a hash of arrays from

2014-07-09 Thread SSC_perl
I'm having a problem creating a hash of arrays. The while loop below works, but it's working too well. ;) Instead of giving me 5 values (from the example data below), it's giving me 25. I don't understand why it seems to be "looping" through the push

Re: creating a hash

2005-07-15 Thread Xavier Noria
On Jul 15, 2005, at 14:50, Octavian Rasnita wrote: I use to put this hash in a file and get the content using my $hashref = do $file; And I want to be able to get the dupplicate keys in order to delete them manually, without needing to search for each manually and compare it with every ot

Re: creating a hash

2005-07-15 Thread Octavian Rasnita
few keys there is no problem, but if there are very many... it is. Thank you. - Original Message - From: "Xavier Noria" <[EMAIL PROTECTED]> To: "Perl Beginners" Sent: Friday, July 15, 2005 3:33 PM Subject: Re: creating a hash > On Jul 15, 2005, at 13:38, Oc

Re: creating a hash

2005-07-15 Thread Xavier Noria
On Jul 15, 2005, at 13:38, Octavian Rasnita wrote: I know that if there are more keys with the same name, the last is used, but I would like to clean the hash. Given $h = { foo => 0, bar => 1, foo => 2 }; what do you mean by "cleaning" $h ? -- fxn -- To unsubscribe, e-mail: [EMAIL

creating a hash

2005-07-15 Thread Octavian Rasnita
Hi, I use to create hash references for using them as config files like: { first_item => '...', second_item => '...', third_item => '...', #... }; Sometimes the hash gets bigger and I can add a new item in the hash that already exists. I know that if there are more keys with the same name, the l

RE: creating a hash out of 2 arrays

2004-04-20 Thread Sanyal, Dibya F \(Corporate, consultant\)
Sanyal, Dibya F (Corporate, consultant) <[EMAIL PROTECTED]> wrote: >: >: I have 2 arrays. One holds all uniq key values of an >: associative list (all ssn), other holds the associated >: values (their names). I need to create a hash by >: putting these arrays together. Each entry in that hash >: w

RE: creating a hash out of 2 arrays

2004-04-20 Thread Bob Showalter
Sanyal, Dibya F (Corporate, consultant) wrote: > Hi, > > I have 2 arrays. One holds all uniq key values of an associative list > (all ssn), other holds the associated values (their names). I need to > create a hash by putting these arrays together. Each entry in that > hash would be (ssn => name).

Re: creating a hash out of 2 arrays

2004-04-20 Thread James Edward Gray II
On Apr 20, 2004, at 9:27 AM, Sanyal, Dibya F ((Corporate, consultant)) wrote: Hi, I have 2 arrays. One holds all uniq key values of an associative list (all ssn), other holds the associated values (their names). I need to create a hash by putting these arrays together. Each entry in that hash

RE: creating a hash out of 2 arrays

2004-04-20 Thread Charles K. Clarkson
Sanyal, Dibya F (Corporate, consultant) <[EMAIL PROTECTED]> wrote: : : I have 2 arrays. One holds all uniq key values of an : associative list (all ssn), other holds the associated : values (their names). I need to create a hash by : putting these arrays together. Each entry in that hash : would be

creating a hash out of 2 arrays

2004-04-20 Thread Sanyal, Dibya F \(Corporate, consultant\)
Hi, I have 2 arrays. One holds all uniq key values of an associative list (all ssn), other holds the associated values (their names). I need to create a hash by putting these arrays together. Each entry in that hash would be (ssn => name). I can iterate over one array and create the hash. Is t

Re: creating a hash list from arrays

2003-10-27 Thread Jeff 'japhy' Pinyan
On Oct 27, radhika sambamurti said: >As per the code below, I am trying to read from the database and put the >values into a hash list, so that I can retrieve the values later. I have >managed to put the values into arrays, but am not able to put them into a >hash. Any ideas how this can be done/i

Re: creating a hash list from arrays

2003-10-27 Thread radhika sambamurti
Hmmm, This did not work. my $count = keys %results_hash; gives me 0 And perl also complained that $results_hash had to be explicitly defined, so I had my $results_hash AND my %results_hash. This is not working. my hash is empty. Radhika On Mon, 27 Oct 2003 21:24:28 -0600 Daniel Staal <[EMAIL PR

Re: creating a hash list from arrays

2003-10-27 Thread Daniel Staal
--On Monday, October 27, 2003 21:22 -0600 Daniel Staal <[EMAIL PROTECTED]> wrote: my $results_hash; Sorry, correction. That should be: my %results_hash; while (my $res = $sth->fetchrow_hashref()) { push(@menu_id, $res->{"menu_item_number"}); push(@menu_desc, $res->{"description"}); $r

Re: creating a hash list from arrays

2003-10-27 Thread Daniel Staal
--On Monday, October 27, 2003 21:51 -0500 radhika sambamurti <[EMAIL PROTECTED]> wrote: Hi, As per the code below, I am trying to read from the database and put the values into a hash list, so that I can retrieve the values later. I have managed to put the values into arrays, but am not able to p

creating a hash list from arrays

2003-10-27 Thread radhika sambamurti
Hi, As per the code below, I am trying to read from the database and put the values into a hash list, so that I can retrieve the values later. I have managed to put the values into arrays, but am not able to put them into a hash. Any ideas how this can be done/improved? ###code below## while

Re: Creating a hash of arrays from row data

2003-07-11 Thread Sudarshan Raghavan
Robin Norwood wrote: To sort-of change the subject, I think the 'deep_copy' subroutine quoted in this article contains a bug... the sub in question: sub deep_copy { my $this = shift; if (not ref $this) { $this; } elsif (ref $this eq "ARRAY") { [map deep_copy($_), @$this]; } elsif (ref $t

Re: Creating a hash of arrays from row data

2003-07-10 Thread Robin Norwood
Sudarshan Raghavan <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] creates an anonymous arrayref by copying the values stored > in @values. perldoc perlref, perldoc perllol > > If you are going use this statement > push @{$ref_to_a}, [EMAIL PROTECTED]; > your while condition must be while (my @v

Re: Re: Creating a hash of arrays from row data

2003-07-10 Thread Jeroen Lodewijks
OTECTED] Date: Thu, 10 Jul 2003 12:26:25 +0100 Subject: Re: Creating a hash of arrays from row data Sudarshan Raghavan wrote: > Rob Dixon wrote: > > > I was perturbed by your post Sardushan. I'll > > try to explain why. > > > > Wait a second, my post was not a

Re: Creating a hash of arrays from row data

2003-07-10 Thread Rob Dixon
Sudarshan Raghavan wrote: > Rob Dixon wrote: > > > I was perturbed by your post Sardushan. I'll > > try to explain why. > > > > Wait a second, my post was not an attempt to undermine Rob > Anderson's post in any manner. I apologize if the wrong message > came out. And I'll also apologize since, al

Re: Creating a hash of arrays from row data

2003-07-10 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Sudarshan Raghavan wrote: > Kevin Pfeiffer wrote: > >>In article <[EMAIL PROTECTED]>, Sudarshan Raghavan >>wrote: >>[...] >> >> >>>Reason: 'shallow copying' vs 'deep copying' >>>Read through this link >>>http://www.stonehenge.com/merlyn/UnixReview/col30.html >>>

Re: Creating a hash of arrays from row data

2003-07-10 Thread Rob Anderson
"Sudarshan Raghavan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Rob Dixon wrote: > > >I was perturbed by your post Sardushan. I'll > >try to explain why. > > > > Wait a second, my post was not an attempt to undermine Rob Anderson's > post in any manner. I apologize if the wrong

Re: Creating a hash of arrays from row data

2003-07-09 Thread Sudarshan Raghavan
Kevin Pfeiffer wrote: In article <[EMAIL PROTECTED]>, Sudarshan Raghavan wrote: [...] Reason: 'shallow copying' vs 'deep copying' Read through this link http://www.stonehenge.com/merlyn/UnixReview/col30.html I looked at this article and tried the code but I get different/wrong results (

Re: Creating a hash of arrays from row data

2003-07-09 Thread Sudarshan Raghavan
Rob Dixon wrote: I was perturbed by your post Sardushan. I'll try to explain why. Wait a second, my post was not an attempt to undermine Rob Anderson's post in any manner. I apologize if the wrong message came out. I sincerely hope that this does not turn Rob away from this list. Giving an answ

Re: Creating a hash of arrays from row data

2003-07-09 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Sudarshan Raghavan wrote: [...] > Reason: 'shallow copying' vs 'deep copying' > Read through this link > http://www.stonehenge.com/merlyn/UnixReview/col30.html I looked at this article and tried the code but I get different/wrong results (or am doing something wr

Re: Creating a hash of arrays from row data

2003-07-09 Thread Rob Dixon
Paul Johnson wrote: > On Wed, Jul 09, 2003 at 11:24:01PM +0100, Rob Dixon wrote: > > > Sudarshan Raghavan wrote: > > > > > Reason: 'shallow copying' vs 'deep copying' > > > Read through this link > > > http://www.stonehenge.com/merlyn/UnixReview/col30.html > > > > How many computer scientists do yo

Re: Creating a hash of arrays from row data

2003-07-09 Thread Paul Johnson
On Wed, Jul 09, 2003 at 11:24:01PM +0100, Rob Dixon wrote: > Sudarshan Raghavan wrote: > > > Reason: 'shallow copying' vs 'deep copying' > > Read through this link > > http://www.stonehenge.com/merlyn/UnixReview/col30.html > > How many computer scientists do you think would know what you > were

Re: Creating a hash of arrays from row data

2003-07-09 Thread Rob Dixon
I was perturbed by your post Sardushan. I'll try to explain why. Sudarshan Raghavan wrote: > Rob Anderson wrote: > > > Hi Jeroen, > > > > > > > > > while (@values = $lcsr->fetchrow) { > > > > > > > > > > This is probably the root of your problem every time you go > > through this loop, you are rep

Re: Creating a hash of arrays from row data

2003-07-09 Thread Rob Anderson
"Sudarshan Raghavan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Rob Anderson wrote: > > >Hi Jeroen, > > > > > > > >>while (@values = $lcsr->fetchrow) { > >> > >> > > > >This is probably the root of your problem every time you go through this > >loop, you are repopulating your ar

Re: Creating a hash of arrays from row data

2003-07-09 Thread Sudarshan Raghavan
Rob Anderson wrote: Hi Jeroen, while (@values = $lcsr->fetchrow) { This is probably the root of your problem every time you go through this loop, you are repopulating your array, put a my before @values. Why do you think this is a problem? All the my would do is create a new lexical @val

Re: Creating a hash of arrays from row data

2003-07-09 Thread Rob Anderson
Hi Jeroen, >while (@values = $lcsr->fetchrow) { This is probably the root of your problem every time you go through this loop, you are repopulating your array, put a my before @values. >$key = shift @values; >$key.= shift @values; > >push @$ref_to_a, [EMAIL PROTECTED]; I don't recog

Creating a hash of arrays from row data

2003-07-09 Thread Jeroen Lodewijks
Hi all, I could use some help with the following problem: I have rows of data (coming in from DBI) looking like this: Key1, Key2, Date_from, Date_to, Value 1, 1, 01-10-2002, 31-10-2002, value1 1, 1, 01-11-2002, 30-11-2002, value2 1, 2, 01-10-2002, 31-10-2002, value3 1, 2, 01-10-2002, 30-10-2002

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Paul Johnson
Ben Siders said: > This is perfect. The input is coming from a CPAN module so I'm fairly > confident that the number of entries will be even, but checking is > always a good idea. If you have warnings on, Perl will whine if it's not. >>You may want to check first that the list has an even numb

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Ben Siders
This is perfect. The input is coming from a CPAN module so I'm fairly confident that the number of entries will be even, but checking is always a good idea. You may want to check first that the list has an even number of entries: die "Invalid parameters" if @_ % 2; but after that it's just

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread LRMK
[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, January 14, 2003 10:57 PM Subject: Question about creating a hash of key-value pairs based on sub parameters. > I have a subroutine that will receive parameters as follows: > > key1, value1, key2, value2, key3, value3, ...

RE: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Dan Muey
> -Original Message- > From: Rob Dixon [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, January 14, 2003 11:17 AM > To: [EMAIL PROTECTED] > Subject: Re: Question about creating a hash of key-value > pairs based on sub parameters. > > > Dan > > "

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Rob Dixon
Dan "Dan Muey" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > This may work : > > &monkey("key","value","key1","value1"); > > sub monkey { > %new_hash = (); > %new_hash = $_[0]; $_[0] is 'key', so this will assign %new_hash = ( key => undef ); You want '%

Re: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Rob Dixon
Hi Ben "Ben Siders" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I have a subroutine that will receive parameters as follows: > > key1, value1, key2, value2, key3, value3, ... keyN, valueN > > I want to create a hash of key1 => value1, key2 => value2, ... , k

RE: Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Dan Muey
day, January 14, 2003 10:57 AM > To: [EMAIL PROTECTED] > Subject: Question about creating a hash of key-value pairs > based on sub parameters. > > > I have a subroutine that will receive parameters as follows: > > key1, value1, key2, value2, key3, value3, ... keyN, valueN

Question about creating a hash of key-value pairs based on sub parameters.

2003-01-14 Thread Ben Siders
I have a subroutine that will receive parameters as follows: key1, value1, key2, value2, key3, value3, ... keyN, valueN I want to create a hash of key1 => value1, key2 => value2, ... , keyN => valueN in the subroutine. I'm curious if there's a Perl "trick" to doing this beyond the obvious loop

Re: creating a hash

2002-03-21 Thread Tor Hildrum
On 21/3/02 15:49, "Trice Dennis D" <[EMAIL PROTECTED]> wrote: > I'm trying to create a hash of the /etc/group file. I need the key to be > the group name and just the members of the group to be the key value. > > Has anyone done this before? > I'm guessing you know how to grab a normal hash f

Re: creating a hash

2002-03-21 Thread Jeff 'japhy' Pinyan
On Mar 21, Trice Dennis D said: >I'm trying to create a hash of the /etc/group file. I need the key to be >the group name and just the members of the group to be the key value. You can use Perl's getgrent() function. setgrent(); while ( my ($name, $members) = (getgrent)[0,3] ) { $gro

creating a hash

2002-03-21 Thread Trice Dennis D
I'm trying to create a hash of the /etc/group file. I need the key to be the group name and just the members of the group to be the key value. Has anyone done this before? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: Creating a hash from a name stored in a variable ...

2001-08-09 Thread Bob Showalter
> -Original Message- > From: Elie De Brauwer [mailto:[EMAIL PROTECTED]] > Sent: Thursday, August 09, 2001 9:01 AM > To: Bob Showalter > Subject: Re: Creating a hash from a name stored in a variable ... > > > > > I searched google, asked some people on irc

RE: Creating a hash from a name stored in a variable ...

2001-08-09 Thread John Edwards
alue of the test key in a couple of the hashes print "This should be a value of 1 <$hash1{test}>\n"; print "This should be a value of 3 <$hash3{test}>\n"; --- code --- John -Original Message- From: Elie De Brauwer [mailto:[EMAIL PROTECTED]] Sent: 09 Au

RE: Creating a hash from a name stored in a variable ...

2001-08-09 Thread Bob Showalter
> -Original Message- > From: Elie De Brauwer [mailto:[EMAIL PROTECTED]] > Sent: Thursday, August 09, 2001 8:43 AM > To: [EMAIL PROTECTED] > Subject: Creating a hash from a name stored in a variable ... > > > I searched google, asked some people on irc but n

Creating a hash from a name stored in a variable ...

2001-08-09 Thread Elie De Brauwer
I searched google, asked some people on irc but no-one could answer me. $max_index is a value gotten from a database which contains the number of entry's for($i = 0, $i < $max_index, $i++){ %data$1{name} = #get the name from the database matching the index and store it here ...

Re: Creating a hash

2001-08-08 Thread Michael Fowler
On Wed, Aug 08, 2001 at 12:20:35PM +, Mel Matsuoka wrote: > %hash = ( >joe => "smith", >jim => ["jones", "taylor"], >sof => "comes", > ); This data structure would require extra checks of the values (i.e. ref($hash{'joe'}) eq 'ARRAY' ? $hash{'joe'}[0] : $hash{'joe'}) each time you

Re: Creating a hash

2001-08-08 Thread Mel Matsuoka
At 03:15 PM 08/08/2001 -0700, Sofia wrote: >I have the following hash of first names and last >names: > >%hash = ( > joe => "smith", > jim => "jones", > sof => "comes", >); > >If for example, jim now has two last names ie jones >taylor, how do I represent that on the hash? You'd basically w

Creating a hash

2001-08-08 Thread Sofia
I have the following hash of first names and last names: %hash = ( joe => "smith", jim => "jones", sof => "comes", ); If for example, jim now has two last names ie jones taylor, how do I represent that on the hash? Thanks in advance again, _