Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Parsing out first names

by Hofmator (Curate)
on Oct 13, 2006 at 07:42 UTC ( [id://578074]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Parsing out first names
in thread Parsing out first names

So do what grep already hinted at, split and keep only the parts you want:
foreach ( @names ) { my @name_parts = split; pop @name_parts if $name_parts[-1] =~ /^[a-zA-Z]\.?$/; # throw last +name away my $f_name = join ' ', @name_parts; print "$f_name\n"; }

Updated code to reflect Not_a_Number's correction, thanks!

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^4: Parsing out first names
by Not_a_Number (Prior) on Oct 13, 2006 at 09:19 UTC
    pop @name_parts; # throw last name away

    Look at the OP's list of names again: some of them are only first names. This code throws "Kurt" away completely, as well as "Jo" in the second "Mary Jo".

    Update: That line can be replaced by:

    pop @name_parts if $name_parts[-1] =~ /^[a-zA-Z]\.?$/;
Re^4: Parsing out first names
by driver8 (Scribe) on Oct 13, 2006 at 12:03 UTC
    That works, but now you just have an obfuscated version of
    foreach my $name ( @names ) { $name =~ s/ [a-zA-Z]\.?$//; print "$name \n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://578074]
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: (5)
As of 2024-04-23 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found