Need help with multi-dimensional arrays was:tie 
Author Message
 Need help with multi-dimensional arrays was:tie


$DB_RECNO) or die "Can't open the stupid file.";
but what I need to do is have a file that holds two element arrays.

Like so:
apple (element 0)
granny smith (element 1)
orange (element 0)
valencia (element 1)

how would/could I do this so array will be array[1][1] would be valencia

(in this example)?

Thanks.



Wed, 18 Jun 1902 08:00:00 GMT  
 Need help with multi-dimensional arrays was:tie


Quote:

> $DB_RECNO) or die "Can't open the stupid file.";
> but what I need to do is have a file that holds two element arrays.

> Like so:
> apple (element 0)
> granny smith (element 1)
> orange (element 0)
> valencia (element 1)

> how would/could I do this so array will be array[1][1] would be valencia

Why wouldn't you use a hash?

$fruits{apple} = ['granny smith', 'gala', 'fuji'];
$fruits{orange} = ['valencia', 'navel', '{*filter*}'];
print $fruits{apple}[1]."\n"; # gala
print $fruits{orange}[0]."\n"; # valencia

Prints:
gala
valencia

Lauren



Wed, 18 Jun 1902 08:00:00 GMT  
 Need help with multi-dimensional arrays was:tie
If I were to do it in in the program file I could and would but how would I do
it if I were pulling an ascii file up?
Quote:




> > $DB_RECNO) or die "Can't open the stupid file.";
> > but what I need to do is have a file that holds two element arrays.

> > Like so:
> > apple (element 0)
> > granny smith (element 1)
> > orange (element 0)
> > valencia (element 1)

> > how would/could I do this so array will be array[1][1] would be valencia

> Why wouldn't you use a hash?

> $fruits{apple} = ['granny smith', 'gala', 'fuji'];
> $fruits{orange} = ['valencia', 'navel', '{*filter*}'];
> print $fruits{apple}[1]."\n"; # gala
> print $fruits{orange}[0]."\n"; # valencia

> Prints:
> gala
> valencia

> Lauren



Wed, 18 Jun 1902 08:00:00 GMT  
 Need help with multi-dimensional arrays was:tie


Quote:

> > $fruits{apple} = ['granny smith', 'gala', 'fuji'];
> > $fruits{orange} = ['valencia', 'navel', '{*filter*}'];
> > print $fruits{apple}[1]."\n"; # gala
> > print $fruits{orange}[0]."\n"; # valencia
> If I were to do it in in the program file I could and would but how would
I do
> it if I were pulling an ascii file up?

Format the datafile like this:

apple|granny smith|gala|fuji
orange|valencia|navel|{*filter*}

Then split it up:




Then you can access them as before:

print $fruits{orange}[1]; # navel

Lauren



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. help: multi-dimensional hash from flat array

2. Help with multi-dimensional array

3. multi-dimensional arrays - more help please!

4. multi-dimensional arrays with hashes help please

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

6. Help: Multi-dimensional arrays & such

7. Help with Multi-dimensional array

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

9. Associative arrays and multi-dimensional arrays.

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

11. Extracting an array out of a multi-dimensional associative array

12. Need Help with putting Hashes in a two-dimensional array

 

 
Powered by phpBB® Forum Software