in reply to Hash not working as intended
... no matter how I reference that [hash] variable ..., [it] always begins at "1".
From the behavior you describe, I strongly suspect you were not running with strictures and warnings enabled; had they been, you would have received some useful hints. In the first example below, run without strictures and warnings, the scalar variable $hash is created and initialized, but there is no %hash hash variable created explicitly; instead, it is autovivified.
>perl -le "my $pbxex = 42; my $hash = $pbxex; ;; for (qw(CS EE EE CS EE)) { $hash{$_}++; printf qq{'$_$hash{$_}' }; } " 'CS1' 'EE1' 'EE2' 'CS2' 'EE3' >perl -wMstrict -le "my $pbxex = 42; my $hash = $pbxex; ;; for (qw(CS EE EE CS EE)) { $hash{$_}++; printf qq{'$_$hash{$_}' }; } " Global symbol "%hash" requires explicit package name at -e line 1. Global symbol "%hash" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
If I correctly understand what you are trying to do, I would think that something like toolic's approach would be best.
|
|---|