|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Not quite clear on what you mean by hasharray. Do you mean an array of hashes, or a hash of arrays?
__________________
- dsb - ![]() Perl Guy |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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! |
|
#5
|
|||
|
|||
|
push'ing to hash arrays
Thanks,
but how do I 'add' [push] new rows to this hash array ref?? trellick |
|
#6
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > push'ing to a hash array ref |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|