#!/usr/bin/perl use strict; use warnings; my %hash; open(ANSWERTALLY, "answertally.dat"); while(<ANSWERTALLY>) { next unless /^Running totals:/ .. /^Averages:/; # by davorg next if /^$/; # next line if empty next if /^Running totals:/; # by davorg last if /^Averages:/; # by davorg my ($key, $value) = split(/:/); # you actually just want to split by + ':' $value =~ s/\s*//g; # remove whitespace globally $hash{$key} = $value unless $value eq ""; # add to hash only if valu +e is holding data } close(ANSWERTALLY); for my $key(sort keys %hash) { print "\$key: $key\t\$hash{\$key}: $hash{$key}\n"; } __END__ __OUTPUT__ $key: Question 1 $hash{$key}: 60 $key: Question 2 $hash{$key}: 123 $key: Question 3 $hash{$key}: 99
In reply to Re: reading from middle of file
by Dietz
in thread reading from middle of file
by guisilva
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |