in reply to incrementing array variables in a text file?
my %votes; my $file = 'vote.txt'; open my $ih, $file or die $! while (<$ih>) { chomp; my ($user, $count) = split ','; $votes{$user} = $count; } close $ih; $votes{sam}++; open my $oh, $file or die $! for my $user (keys %votes) { print $oh "$user,$votes{$user}\n"; } close $oh;
On a side note, your code wasn't working because you weren't outputted a return for each record:
# From print VOTE $user[$count]."|".$vote[$count]; # To print VOTE $user[$count]."|".$vote[$count]."\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: incrementing array variables in a text file?
by friar tux (Novice) on Apr 30, 2011 at 23:00 UTC | |
by wind (Priest) on Apr 30, 2011 at 23:05 UTC | |
by friar tux (Novice) on Apr 30, 2011 at 23:34 UTC | |
by wind (Priest) on May 01, 2011 at 00:09 UTC | |
by poj (Abbot) on May 01, 2011 at 12:03 UTC | |
by friar tux (Novice) on May 01, 2011 at 17:11 UTC | |
by poj (Abbot) on May 01, 2011 at 20:05 UTC | |
by friar tux (Novice) on May 02, 2011 at 16:51 UTC |