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,
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
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
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;
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
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
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
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 $
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
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
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
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
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).
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
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
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
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
--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
--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
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
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
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
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
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
>>>
"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
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 (
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
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
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
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
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
"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
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
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
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
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
> -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
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
> -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.
>
>
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
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
41 matches
Mail list logo