Help understanding Lists of Lists or Multi-dimensional arrays 
Author Message
 Help understanding Lists of Lists or Multi-dimensional arrays

First, I've read and re-read Programming Perl pg 257-264.  Also Perl
Cookbook
pg 97-105 I don't understand them
.
I've gotten my program so far but can't continue.  What I want to be able to
do
is retrieve data by the following variable:

unit (key(data)), so far I have all the key,value pairs in the unit arrays.
In Programming
Perl it talks of retrieveing data using $LoL[2][2].  Can you do something
like:
Variables $unit $key and retieve data from the List of Lists by using
$LoL[$unit][$key]?

I guess I don't know how to get the List of Lists.  I currently have 12

contain key=value pairs.  I don't know how to get to using
$LoL[$unit][$key].

Any help understanding this would be of help.

TIA - Jody

PS - I know there isn't any use strict.

The Program:
#!c:/perl -w

%unit = (
akrn => "Akron Ward",
alli => "Alliance Ward",
ashl => "Ashland Branch",
can1 => "Canton Ward",
can2 => "Canton II Ward",
medi => "Medina Ward",
newp => "New Philadelphia Ward",
root => "Rootstown Ward",
stow => "Stow Branch",
tall => "Tallmadge Ward",
wads => "Wadsworth Branch",
woos => "Wooster Ward",
);

$yr = "2001"; $mo = "01"; # Will be variable in live program

print "Checking for files\n";


 $filename = "c:/www/reports/$yr$mo$unit.dat";
 if (-e "$filename") { print "$filename exists\n"; &process; &pause;}
 else { print "$filename does not exist!\n"; }

Quote:
}



 }

sub process {
 $in = "";
 open (INFILE, "$filename" ) or die "Can't open $filename: $!\n";
  while (<INFILE>) {$in .= $_;}
 close (INFILE) or die "Can't close $filename: $!\n";




       ($name, $value) = split(/=/, $inrec);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;
   $ins{$name} = $value;
 print "\$ins{$name} = $ins{$name}\n"; # for de-bug only
 }

Quote:
}

sub pause {

 print "\nPress Enter to Continue\n";
 chomp ($inkey = <STDIN>);

Quote:
}

-----------------------------------------------------------------
The Data:

file: 200101woos.dat

unit=woos
childnoattend=15
mnoph=1
totsplit=34
ymnoattend=15
copycount=0
firstnoattend=1
month=01
totyw=21
first=6
vt=77
totfam=168
totpe=52
ywnoattend=9
totschild=15
totend=106
year=2001
penoattend=54
totht=92
totmp=51
wnoattend=61
totmem=338
norec=31
pass=cccc
mpnoattend=12
totchild=52
report=report
totym=26
totwomen=121
avgsm=196

file: 200101medi.dat

unit=medi
childnoattend=4
mnoph=0
totsplit=13
ymnoattend=5
copycount=0
firstnoattend=0
month=01
totyw=20
first=2
vt=72
totfam=128
totpe=33
ywnoattend=2
totschild=13
totend=90
year=2001
penoattend=32
totht=68
totmp=55
wnoattend=50
totmem=272
norec=28
pass=6666
mpnoattend=7
totchild=40
report=report
totym=12
totwomen=99
avgsm=143



Mon, 04 Aug 2003 11:57:10 GMT  
 Help understanding Lists of Lists or Multi-dimensional arrays

Quote:

>First, I've read and re-read Programming Perl pg 257-264.  Also Perl
>Cookbook
>pg 97-105 I don't understand them
>..

I'd recommend that you read the following documentation :

1) perldoc perldata
2) perldoc perldsc
3) perldoc perlfaq4

If I understand your description correctly, you're looking for a hash of
hashes, and not an array of arrays...

After you've gone through those three and solved your problem, have a
quick look at perllol, perlreftut and perlref as well for later use.

HTH,

Michel.



Mon, 04 Aug 2003 20:08:52 GMT  
 Help understanding Lists of Lists or Multi-dimensional arrays

Quote:



>>First, I've read and re-read Programming Perl pg 257-264.  Also Perl
>>Cookbook
>>pg 97-105 I don't understand them
>>..

>I'd recommend that you read the following documentation :

>1) perldoc perldata
>2) perldoc perldsc
>3) perldoc perlfaq4

I'm reading these over AGAIN and trying to understand the
hash, array, list, reference, dereference thing.  It's difficult.

Quote:
>If I understand your description correctly, you're looking for a hash of
>hashes, and not an array of arrays...

>After you've gone through those three and solved your problem, have a
>quick look at perllol, perlreftut and perlref as well for later use.

Thanks Michel,

            This is probably what I need but I don't understand this yet.
Old
Basic Programmers die hard.  If I could just use array$(1,2) and get
the answers I need! :-)

Jody



Thu, 07 Aug 2003 10:49:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linked list/multi-dimensional array emulation

2. multi-dimensional lists

3. problem printing multi-dimensional lists

4. Trying to understand lists of lists

5. List of lists or array of lists in Perl

6. List of lists or array of lists in Perl

7. help sorting list of lists/nested array

8. two-dimensional arrays, lists, whatever

9. help: multi-dimensional hash from flat array

10. Help with multi-dimensional array

11. multi-dimensional arrays - more help please!

12. multi-dimensional arrays with hashes help please

 

 
Powered by phpBB® Forum Software