Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Pattern match array

by thezip (Vicar)
on May 07, 2008 at 15:09 UTC ( #685231=note: print w/replies, xml ) Need Help??


in reply to Pattern match array

This would better be coded using a hash:
use strict; use warnings; my %prims =( "int" => 1, "char" => 1, "long" => 1, "double" => 1, "static" => 1 ); while(<>) { if($prims{$_}) { print "Found item $_\n"; } }
Update:
If you absolutely need to have the @prim array, then create the hash on-the-fly using map:
... my @prim = (("int","char","long","double","static"); my %prim = map { $_ => 1 } @prim; ...
Update2

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.


Your wish is my commandline.

Replies are listed 'Best First'.
Re^2: Pattern match array
by moritz (Cardinal) on May 07, 2008 at 15:16 UTC
    But it doesn't do the same thing. aennen searches for substrings, you search for exact matches.

    The fact that the lines aren't chomped means that you'll never get a match (unless on the last line, if it lacks a newline).

Re^2: Pattern match array
by aennen (Acolyte) on May 07, 2008 at 15:25 UTC
    Sorry should have expanded on input.
    Input is source code and I am trying to match
    the pattern in a string of data

    Example input date line

    int EB_Column::beginNPColumn(const bfpd_nc_t& i_rec, BF_COORDINATE_C_D(i_x))

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685231]
help
Chatterbox?
[Corion]: Hmmm - Mano Negra or at least Manu Chao seem to put on a good live show. At least the one live CD I have from Manu Chao sounds good ;)
Discipulus feels the same jealousity of the johngg's daughter
[1nickt]: choroba I agree
[choroba]: Playing in a punk rock band for 20 years... my hearing is quite bad
[Corion]: I still have hopes to turn my godson and his two siblings into a punk band ;)
[Corion]: Their older sister just started piano but has been interested in drumming, which she should be able to start with 8 years or so)
[Discipulus]: ah was Kink of Bongo 1992..
[1nickt]: choroba name of band? youtube link? MySpace link?

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-03-24 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.