Home > Archive > PERL Beginners > May 2006 > map array to hash
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| John Ackley 2006-05-29, 7:59 am |
| there is more than one way to do it
is there an easier way to do this map:
my $index = 0;
while( my @a = $SQL->fetchrow_array) {
my %a = map { $fieldnames[$index++] => $_ } @a;
print "$_ => $a{$_}\n" for (keys %a);
}
| |
| Paul Johnson 2006-05-29, 7:59 am |
| On Mon, May 29, 2006 at 09:16:00AM -0400, John Ackley wrote:
> there is more than one way to do it
> is there an easier way to do this map:
>
> my $index = 0;
> while( my @a = $SQL->fetchrow_array) {
> my %a = map { $fieldnames[$index++] => $_ } @a;
my %a;
@a{@fieldnames} = @a;
> print "$_ => $a{$_}\n" for (keys %a);
> }
--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
| |
| John Ackley 2006-05-29, 6:59 pm |
|
Jenda Krynicky wrote:
> From: John Ackley <john@ackley.net>
>
>
> Any reason why you are not using fetchrow_hashref()?
>
thanks! yes, I did not RTFM
|
|
|
|
|