What's wrong? I found out, if you define %count outside the foreach loop with my %count; and omit "my" within the loop, it's working. But "my" within the loop results in the mentioned warning.#!/usr/bin/perl use warnings; use strict; chomp(my @words = <STDIN>); foreach my $word (@words) { my $count{$word} += 1; } foreach my $key (sort keys %count) { print "$key was found $count{$key} times\n"; }
In reply to Syntax error - "my" within foreach loop by Klammer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |