Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How can you check if a word in a array occur in another array?

by tobyink (Abbot)
on Nov 29, 2012 at 08:49 UTC ( #1006199=note: print w/ replies, xml ) Need Help??


in reply to How can you check if a word in a array occur in another array?

This line:

@words = split(/ /, $word);

... replaces the @words array each time around the loop. So when you're finished looping, @words will only contain words from the last line of the file, words from the previous lines having been discarded.

What you want is:

push @words, split(/ /, $word);

I leave @EN = split(/ /, $word) as an exercise for the reader.

Also, I concur with frozenwithjoy in that a hash is more likely to suit your needs than an array.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: How can you check if a word in a array occur in another array?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006199]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-09-03 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls