
geest
Deleted
May 1, 2001, 1:28 PM
Post #3 of 3
(175 views)
|
complex data structures should be handled by hashes of hashes $data_file = "daten.txt"; open DATA_FILE, "$data_file" or die "Can't open $data_file: $!\n"; $author = {}; while (<DATA_FILE>) { if ( /(^Author \(id number\) :)\s+(.+)/ ) { $id = $2; $author->{$id} ={}; } elsif ( /(^\D+)\s:\s+(.+)/ ){ $key = $1; $value = $2; $author->{$id}->{$key} = $value; } else { $author->{$id}->{'rest'} .= $_; } } # output foreach $id (keys %$author) { print "$id\n"; foreach $id_field (keys %{$author->{$id}}) { print $id_field ,":", $author->{$id}->{$id_field}, "\n"; } }
|