Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to club different lines of program into one

by McDarren (Abbot)
on May 25, 2009 at 14:42 UTC ( [id://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 missing.pl #!/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 missing.pl 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,
Darren

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found