how to build two dimensional array? 
Author Message
 how to build two dimensional array?



Quote:

>|> Note also that Perl 5 has explicit support for multi-dimensional arrays
>|> (implemented as arrays of arrays (of arrays (of arrays...))):
>|>
>|>     $table[3][1] = 10;
>|>     $table[3][2] = 12;
>|>
>|> You can intermix numeric and string subscripts too:
>|>
>|>     $table[2]{'dog'}[1] = 10;
>|>     $table[2]{'cat'}[2] = 12;
>|>
>|> Larry

>     I tried this once, but ran into weird problems.  Eg.  I had
>assignments like:

>   $host{$net}{$addr} = "nodename";

>and then wished to do something like:

>   foreach $n (keys %host) {         # This was ok..,gave all $NET values
>      foreach $a (keys %host{$n}) {  # Fails, as %host{$n} is illegal

Try:
       foreach $a (keys %{host{$n}}) { ...
                         ^        ^
Note additional {}'s

Quote:

>--

>The contents of this message *may* reflect my personal opinion.  They are
>*not* intended to reflect those of my employer, or anyone else.

You didn't think Larry would really leave us high and dry with this one?

Hope this helps.
Jim



Sat, 17 Jan 1998 03:00:00 GMT  
 how to build two dimensional array?


Quote:
>     I tried this once, but ran into weird problems.  Eg.  I had
>assignments like:

>   $host{$net}{$addr} = "nodename";

>and then wished to do something like:

>   foreach $n (keys %host) {         # This was ok..,gave all $NET values
>      foreach $a (keys %host{$n}) {  # Fails, as %host{$n} is illegal

Not having easy access to perl5 right now I can't test this, but you
don't get automagical dereferencing in perls o you have to be explicit e.g.

  foreach $net (keys %host)
  {
    foreach $addr (keys %{$host{$n}})
    {

but I could be horribly wrong :-)

Hope this helps,

Mike
--
Mike Stok                        | The "`Stok' disclaimers" apply.


http://www.{*filter*}com.net/~stok/   | The inevitable WWW page (?)



Sat, 17 Jan 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to build two dimensional array?

2. how to build two dimensional array?

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

4. Associative array of a two dimensional array

5. 2-dimensional array into 1 dimensional array?

6. Reading into a two-dimensional array from STDIN

7. two-dimensional arrays

8. Two dimensional array

9. Different ways of initialising a two dimensional array

10. Dynamic Two-Dimensional Array Creation?

11. two-dimensional arrays, lists, whatever

12. sort a two-dimensional array....

 

 
Powered by phpBB® Forum Software