in reply to Pattern match array
Update:use strict; use warnings; my %prims =( "int" => 1, "char" => 1, "long" => 1, "double" => 1, "static" => 1 ); while(<>) { if($prims{$_}) { print "Found item $_\n"; } }
Update2... my @prim = (("int","char","long","double","static"); my %prim = map { $_ => 1 } @prim; ...
After reading moritz's take on this, his seems to be what you're looking for.
I was somehow thinking that you were parsing chunks (ie. words) and then seeing if that word existed in your array/hash.
moritz is also spot-on mentioning that you're not handling the newlines at the ends of lines.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pattern match array
by moritz (Cardinal) on May 07, 2008 at 15:16 UTC | |
|
Re^2: Pattern match array
by aennen (Acolyte) on May 07, 2008 at 15:25 UTC |