Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: How to club different lines of program into one

by McDarren (Abbot)
on May 25, 2009 at 14:42 UTC ( #766048=note: print w/replies, xml ) Need Help??

in reply to How to club different lines of program into one

I think part of your question is missing. That is, you haven't specified which of the words in your file are supposed to be present and which are not.

But in any case, consider the following:

darren@dino:~/perl$ cat words.txt january february egypt moon saturday darren@dino:~/perl$ cat #!/usr/bin/perl use strict; use warnings; my $word_file = 'words.txt'; my @required_words = qw/january larry_wall february holiday egypt moon + saturday/; my %words; open my $in, '<', $word_file or die "$!\n"; while (my $line = <$in>) { chomp $line; $words{$line}++; } close $in; for my $word (@required_words) { if ($words{$word}) { print "Required word $word is present\n"; } else { print "Required word $word is missing\n"; } } darren@dino:~/perl$ perl Required word january is present Required word larry_wall is missing Required word february is present Required word holiday is missing Required word egypt is present Required word moon is present Required word saturday is present

Hope this helps,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://766048]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-04-21 08:36 GMT
Find Nodes?
    Voting Booth?