Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 28th, 2001, 09:58 AM
trellick trellick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 14 trellick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question push'ing to a hash array ref

Hi there,

got a hasharray ref from a mysql query

col_a -> "val1" col_b-> "val2"
col_a -> "val3" col_b-> "val3"

and I use it:

foreach $row ($@hash_ref))
{
$newval=$row->{col_a}++; #whatever
# do some work
....
}

But afterwards I need to 'add' a new hasharray to this ref. How can I do it?

push? how?


trellick

Reply With Quote
  #2  
Old June 28th, 2001, 12:22 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Not quite clear on what you mean by hasharray. Do you mean an array of hashes, or a hash of arrays?
__________________
- dsb -
Perl Guy

Reply With Quote
  #3  
Old June 28th, 2001, 03:01 PM
trellick trellick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 14 trellick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
pushin' to hash_array

hi there,

to be honest, I'm not quite sure of the terminology, but as far as I understand an array of hashes.....

i.e. I call a query to mysql within perl

$hash_ref=$myquery->fetchall_arrayref( {col_a=>1, col_b=>1});

This query in mysql could return thousands of 'rows'. [hash arrays?] but always, of course with the same column names [keys?].

In this case 'col_a' and 'col_b'

So the vary in $hash_ref after the call is a reference to an array of hashes(?)


Sorry to be vague,



trellick.

Reply With Quote
  #4  
Old June 28th, 2001, 04:51 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Thumbs up

if your using the fetchall_arrayref(), this maybe a bit easier.

Code:
my $data = $sth->fetchall_arrayref({});
for my $results (@{$data}) {
# do something with $results->{'col_name'}
}


Mickalo
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
  #5  
Old July 2nd, 2001, 02:11 AM
trellick trellick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 14 trellick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
push'ing to hash arrays

Thanks,


but how do I 'add' [push] new rows to this hash array ref??



trellick

Reply With Quote
  #6  
Old July 2nd, 2001, 10:03 AM
trellick trellick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Posts: 14 trellick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
push'ing to a hash array ref

Hi there,

I've got a solution:

push(@{my_href},{"col_a"=>$new_a_val, "col_b"=>$new_b_val});



thanks


trellick

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > push'ing to a hash array ref


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT