Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to club different lines of program into one

by GrandFather (Saint)
on May 25, 2009 at 23:48 UTC ( [id://766108]=note: print w/replies, xml ) Need Help??


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

If you use a hash to record your results you don't need to slurp the file and can generate a little more information. Consider:

use strict; use warnings; my %matches = map {$_ => 0} qw(january february egypt); while (<DATA>) { chomp; ++$matches{$_} if exists $matches{$_}; } for my $word (sort keys %matches) { if (! $matches{$word}) { print "Didn't find $word.\n"; } elsif (1 == $matches{$word}) { print "Found $word once.\n"; } else { print "Found $word $matches{$word} times.\n"; } } __DATA__ january february january moon saturday

Prints:

Didn't find egypt. Found february once. Found january 2 times.

True laziness is hard work

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2026-03-17 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.