#!perl -w # # Demostration of the extraction of Meta-data through hashes of arrays # # Edgar Brown, Apr 14, 2001 # All the traditional disclaimers apply ;) # # read all the file in open( FILE , " ); close( FILE ); # extract the META data tags and place them in a hash while ($tmp =~ s/^\%META:([^{}\%]+)\{(.*)\}\%\n//mo){ if ($meta{$1}) { # $meta{$1} = [ @{ $meta{$1} } , $2 ]; #generate a hash of arrays push @{$meta{$1}}, $2 ; #generate a hash of arrays } else { $meta{$1} = [ $2 ]; # could be used for flags in the meta-data (meta-meta-info?) } } # now print the contents of the hash foreach $tag (keys %meta){ $count = 0; print "\n====== $tag ".@{ $meta{ $tag } }." element(s)\n"; foreach ( @{ $meta{ $tag } } ){ print "${tag}[$count] => $_ \n"; $count++; } # Alternatively: # for $i (0..$#{ $meta{$tag}}) { # print "${tag}[$i] => $meta{$tag}[$i] \n" # } } # And print the remaining text print "\n\n======= Remaining text from metadata file:\n"; print $tmp;