Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

error asking pakage namewhile using hashes

by Anonymous Monk
on Oct 06, 2013 at 04:47 UTC ( #1057111=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

my(@words, $count, $word); chomp(@words =<STDIN> ); foreach $word (@words) { $count{$word} += 1; #or $count{$word}++; } foreach $word (keys %count){ }

this gives an error requires package name..any one plz help me thanks in advance

Replies are listed 'Best First'.
Re: error asking pakage namewhile using hashes
by boftx (Deacon) on Oct 06, 2013 at 05:30 UTC

    Well, assuming you have a use strict; that you did not include in the code sample then %count is not being explicitly defined. You are declaring $count, but you are using it as a hash, $count{$word}. Change $count to %count and it should be okay.

    my(@words, %count, $word);

    Update: added explicit example of where to make the change.

    On time, cheap, compliant with final specs. Pick two.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057111]
Approved by Athanasius
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2016-12-03 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (56 votes). Check out past polls.