Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Re: regex: seperating parts of non-formatted names

by jkahn (Friar)
on Sep 09, 2002 at 18:48 UTC ( #196391=note: print w/replies, xml ) Need Help??

in reply to Re: regex: seperating parts of non-formatted names
in thread regex: seperating parts of non-formatted names

I can't agree enough.
You will save yourself brain hurt by tokenizing first, so at least you have some idea where the word boundaries are in some reliable way. Then you need the predicate functions, as the previous poster pointed out.
Perhaps the following snippet makes sense:
sub parse_names @uncategorized = tokenize($erstwhile_name); push (@titleToks, shift @uncategorized) until ( not is_title($uncategorized[0]) or not @uncategorized ); if (not @uncategorized) { warn "all titles!"; return; } push (@nameToks, shift @uncategorized) until ( not is_name($uncategorized[0]) or not @uncategorized ); # now probably want to break up @nameToks into first and # last names; this probably involves specific lists like # "van" and "von" and "de" so you attach "de Sade", "van # Gogh" to the last name, but "Robert Louis" to the first # name if (@uncategorized) { # must be suffixes like "III", "Jr.", etc @suffixes = @uncategorized; } if (not is_acceptable_suffix(@suffixes)) { warn "problem with suffixes " . join " ", @suffixes; } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196391]
[shmem]: for instance: for (@array) { $_ += 1 }; - here $_ inside the loop is an alias for the current element of @array
[james28909]: having to juggle between machines and perl versions and guis and compiling to a portable binary is slightly redundant when i could just use c or something
[shmem]: james28909: you'll prolly come back to perl when done :-P
[james28909]: but isnt that the same a referencing?
[shmem]: no. A reference is something like a pointer in C
[james28909]: i mean i get what you are saying though. but it is easily confused (especially by someone like me :P )
[shmem]: in the loop example I gave you, $_ is not a reference. It is just the current element of @array "in disguise".
[shmem]: i.e accessed as $array[$i] where $i would be the loop index in a C-style "for" loop: for($i=0;$i<=$# array;$i++){ ... }</c>
[james28909]: i gotcha

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2018-05-20 15:55 GMT
Find Nodes?
    Voting Booth?