RE: Creating a hash of arrays from

2014-07-10 Thread Sunita Pradhan
You can try using a reference instead of hash like : -- my $entries; my($state, $zipcodes); while (my $line = ) { chomp $line; ($state, $zipcodes) = split (/=/, $line); push( @{ $entries->{$state} }, split( /,/,$zipcodes) ) } print Dumper ($entries); __DATA__ AK=995,

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 $

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

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

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

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

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

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
Here is a way of doing this. Tested and commented. But, like Bob says, you may well end up loosing track of what hashes you've created... --- code --- @indexNumbers = qw(1 2 3 4); foreach $number(@indexNumbers) { $hashname = "hash$number"; # Create a scalar with the name of the hash you

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 no-one could > answer me. > >

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