in reply to help with "use strict" and code organization
use strict; use warnings; my $savegame = 0; my $deathcnt = 0; ... then initialize the rest of your vars ... ... read the log file and accumulate the counts for each variable ...
my $msgformat = "You have obtained %d %s.\n"; if ($shotgobt) { printf $msgformat, $shotgobt, "shotguns") }; if ($armorobt) { printf $msgformat, $armorobt, "Armors") }; ... do the same type of thing for the rest of the messages ...
As you parse your log file, you'll just accumulate the values into the appropriate hash keys. Then it's just a matter of printing out the keys and their values, like:my %stats = ( 'clips' => 6, 'boxes of ammo' => 2, 'shells' => 47, 'boxes of shells' => 3, 'shotguns' => 2, 'Armors' => 2, 'health bonuses' => 1, 'medikits' => 4, 'stimpacks' => 2, 'yellow keycards' => 1, 'backpacks' => 1, 'berserk packs' => 1, );
my $msgformat = "You have obtained %d %s.\n"; for my $stat (keys %stats) { printf $msgformat, $stats{$stat}, $stat; }
|
|---|