Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Dealing with Names

by GrandFather (Saint)
on Aug 28, 2008 at 21:19 UTC ( [id://707602]=note: print w/replies, xml ) Need Help??


in reply to Dealing with Names

I presume your problem is that you have the names stored disassembled in an array. So reassemble the names using a character that won't occur in the name text as a part separator, perform the fix up, then disassemble the string again:

use strict; use warnings; my $match = join '|', 'Von', 'De La', 'De', 'La'; my @names = map {chomp; [split]} split "\n", <<NAMES; Daniel R Von Vanderschmidt Daniel Von Vanderschmidt Daniel De La Silvia Daniel De Silvia Daniel La Silvia NAMES for my $name (@names) { my $nameStr = join '~', @$name; $nameStr =~ s/~($match)~/~$1 /g; $name = [split '~', $nameStr]; } print join ('|', @$_), "\n" for @names;

Prints:

Daniel|R|Von Vanderschmidt Daniel|Von Vanderschmidt Daniel|De La Silvia Daniel|De Silvia Daniel|La Silvia

Perl reduces RSI - it saves typing

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found