in reply to Dealing with Names

Please show the Perl code you have tried thus far. Enclose the code in "code" tags, as described in Writeup Formatting Tips.

Also, show the exact output you get, any error/warning messages, and the exact output you expect, again in code tags.

Replies are listed 'Best First'.
Re^2: Dealing with Names
by walkingthecow (Friar) on Aug 28, 2008 at 18:46 UTC
    @name_breakdown=split(/ /,$new_gecos); if ($name_breakdown[1] eq "de" || $name_breakdown[1] eq "von" || $name +_breakdown[1] eq "van" or $name_brea kdown[1] eq "der" || $name_breakdown[1] eq "la" || $name_breakdown[1] +eq "del" || $name_breakdown[1] eq "el" || $name_breakdown[1|2] eq "le") { if ($name_breakdown[2] && $name_breakdown[3]) { $name_breakdown[1] = join(' ', $name_breakdown[1], $name_breakdow +n[2], $name_breakdown[3]); @END = splice(@name_breakdown, -2); } else { $name_breakdown[1] = join(' ', $name_breakdown[1], $name_breakdow +n[2]); pop @name_breakdown; } }
    This does not work because what if there is a middle intial (Daniel R De La Silva), it messes up. It does work if it is "Daniel De La Silva" though.
      • Turn the above into a subroutine, passing the subscript of $name_breakdown you wish to test (rather than 1).
      • Modify the code to use the parameter, rather than hardcoding 1, 2, and 3.
      • Return whether or not not the replacement took place.

      Call the routine with a parameter of 1. If it does not do the replace, call it with a parameter of 2.
      (If you're really ambitious, store the name prefaces in a hash, and use the hash as a test. Sooner or later, the list will change...)