multi-dimensional arrays with hashes help please 
Author Message
 multi-dimensional arrays with hashes help please

Now, I know this code will not work:

$founddata[0]{'name'}='Chris';
$founddata[0]{'age'}='27';
$founddata[1]{'name'}='Fred';
$founddata[1]{'age'}='Fred';

$cnt=0;

    foreach $key (keys %founddata[$cnt]){
        print "$founddata[$cnt]{$key}\n\n";
        }
    $cnt++;
    }

But I need to do the same with legitimate code, anyone know how?

Thanks in advance!

Chris Denman



Tue, 10 Jul 2001 03:00:00 GMT  
 multi-dimensional arrays with hashes help please
Re: multi-dimensional arrays with hashes help

Chris> Now, I know this code will not work:
Chris> $founddata[0]{'name'}='Chris';
Chris> $founddata[0]{'age'}='27';
Chris> $founddata[1]{'name'}='Fred';
Chris> $founddata[1]{'age'}='Fred';

$founddata{0}{name} = ...

and so on.

Then you can double walk the hash keys.

    foreach $index ( keys %founddata ) {
        foreach $attr ( keys %{$founddata{$index}} ) {
            print "$index $attr $founddata{$index}{$attr}\n";
        }
    }

hth
tony
--
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien.  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:



Tue, 10 Jul 2001 03:00:00 GMT  
 multi-dimensional arrays with hashes help please
Only one minor change... :)

Quote:

> Now, I know this code will not work:

> $founddata[0]{'name'}='Chris';
> $founddata[0]{'age'}='27';
> $founddata[1]{'name'}='Fred';
> $founddata[1]{'age'}='Fred';

> $cnt=0;

>     foreach $key (keys %founddata[$cnt]){

     foreach $key (keys %{$founddata[$cnt]}){

Fixes it.

Quote:
>         print "$founddata[$cnt]{$key}\n\n";
>         }
>     $cnt++;
>     }

> But I need to do the same with legitimate code, anyone know how?

> Thanks in advance!

> Chris Denman

Lee.

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Lee Benfield, Ford Motor Co.



Tue, 10 Jul 2001 03:00:00 GMT  
 multi-dimensional arrays with hashes help please
I would suggest an array of hash-references in your case. Consider the
following code:

/whichever/path/perl -w
use strict;



hash

# and so on.....


    foreach $key (keys %$one) {
        print "$key : $one->{$key}\n\n";
    }

Quote:
}

HTH
-Partha
Quote:

> Now, I know this code will not work:

> $founddata[0]{'name'}='Chris';
> $founddata[0]{'age'}='27';
> $founddata[1]{'name'}='Fred';
> $founddata[1]{'age'}='Fred';

> $cnt=0;

>     foreach $key (keys %founddata[$cnt]){
>         print "$founddata[$cnt]{$key}\n\n";
>         }
>     $cnt++;
>     }

> But I need to do the same with legitimate code, anyone know how?

> Thanks in advance!

> Chris Denman



Tue, 10 Jul 2001 03:00:00 GMT  
 multi-dimensional arrays with hashes help please

Quote:

> I would suggest an array of hash-references in your case. Consider the
> following code:

Isn't that what the original poster had?
Quote:


> > Now, I know this code will not work:

> > $founddata[0]{'name'}='Chris';
> > $founddata[0]{'age'}='27';
> > $founddata[1]{'name'}='Fred';
> > $founddata[1]{'age'}='Fred';



Tue, 10 Jul 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. multi-dimensional arrays - more help please!

2. help: multi-dimensional hash from flat array

3. Incrementing a Multi-dimensional Hash Array

4. Help with multi-dimensional array

5. Help understanding Lists of Lists or Multi-dimensional arrays

6. Help: Multi-dimensional arrays & such

7. Help with Multi-dimensional array

8. Need help with multi-dimensional arrays was:tie

9. Weird Hash w/ n-dimensional two-dimensional array !!!!!!

10. arrays, multi-dimensional arrays, pointers and such

11. Associative arrays and multi-dimensional arrays.

12. Multi-Dimensional arrays, DBMs, and Assoc. Arrays

 

 
Powered by phpBB® Forum Software