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

Re: Extract names

by ww (Archbishop)
on Feb 18, 2013 at 15:20 UTC ( #1019353=note: print w/replies, xml ) Need Help??

in reply to Extract names

We probably need more info to help.
  1. How do you define "names"?
  2. When you say "from a regex" do you mean the names are in a regular expression like  /sue mike fred rover/ or did you intend to ask how to extract names using a regex?
  3. What does your editor have to do with the question?

Despite the danger in making assumptions, on a guess that you mean how does one extract names from a text document which contains names and other words, you may find some benefit from the following:

a. Create an array with the names you want to extract (perl can do most anything, but washing windows and differentiating between names and other words are out of scope. See Tutorials)

b. Slurp or read line-by-line (depending on the size of the document) the text file. open and, again, the tuts here.

c. Test (see perlre, perlretut, et al_, word-by-word (for values of word meaning preceded or followed by a space, punctuation or EOL) in the line or file for matching against any of your array elements (names).
  If reading line-by-line, rinse and repeat.

d. Capture the words that match names (see Tuts, the regex docs, etc) -- probably to an array with something like push @names_found, $name.

e. Do something with the array.

And, in deference to the values of the Monastery and those from whom you ask help, you might wish to read some of the documents that lay out what are considered "good practices" here at PerlMonks I know what I mean. Why don't you?, On asking for help and How do I post a question effectively?.

If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019353]
[Corion]: I feel a cold coming on - I guess I'll try to get through this day (visit to my godson this evening) and then a hot tub and tomorrow work from home, or not at all...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2018-03-20 09:22 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.