
Jono
stranger
Aug 17, 2001, 7:58 AM
Post #1 of 2
(312 views)
|
Hi, I want to do this sort of thing: open INFILE2, "$prf" or die "cannot open address.txt: $!\n"; #Array will hold pointers to arrays, ie: #@struct = (['name1', 'addr1'], # ['name2', 'addr2'], # etc... ); my @records; while(INFILE2) { my ($name, $addr); #Grab 3 lines and store them, quitting on EOF: ($name, undef, $address) = (<INFILE2>, <INFILE2>, <INFILE2>) or last; #Push new data into array: push @records, [$name, $address]; #Skip lines until we see a divider. while(<INFILE2>) { last if /----------/; } print "<TR><TD>$name</TD><TD>$address</TD></TR>"; } close INFILE2; for each record for an undefined number of records. Each one is separated by "----------" and the file I'm reading is basically just a text file, each record can be any length, but the first three lines contain Name, ??, E-mail address of each person the record exists for. Once I've got the first three lines I want to move onto the next record and just ignore the rest of the lines in the record. Does that make sense? Basically I want to store this data in some array (of arrays?) hence the @struct part in the code...and then use the data later in the program. Like just run through the arrays of the three lines, use the last element (e-mail address) then move onto the next one. This code here only displays the data from the first record, Any ideas why? I would like to print out the data for each record, for the number of records in each file (I'm running through lots of files) there can be between 1 and ~1000 records in each file. Please try to help if you can...:) Cheers, Jono
|