Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Extract names

by ww (Bishop)
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!


Comment on Re: Extract names
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-08-22 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (167 votes), past polls