in reply to Parsing out first names

You could subsitute out the last Single chatacter with or without a period "."

You also had an anonymous array ref in your @names array. Fixed in the below code.
#!/usr/bin/perl -w use strict; use Data::Dumper; my @names = ( "Mark K.", "Bob H", "Kurt", "Mary Kay K", "Mary Jo Z.", "Mary Jo" ); foreach my $name ( @names ) { $name =~ s/ [a-zA-Z].?$//; print "$name \n"; }
Prints:
Mark Bob Kurt Mary Kay Mary Jo Mary

Replies are listed 'Best First'.
Re^2: Parsing out first names
by driver8 (Scribe) on Oct 13, 2006 at 07:10 UTC
    Sorry to nitpick, but it needs to be: $name =~ s/ [a-zA-Z]\.?$// Yours chopped the "Jo" off of the second Mary Jo :(