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 statement. If someone cou

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