rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
but was trying to get it down to one line. can anyone tell me why this is not working:sub fullname { my (@parts) = @_; my $name = join(" ", @parts); $name =~ s/^(.) /$1\. /g; $name =~ s/ (.) / $1\. /g; $name =~ s/ (.)$/ $1\./g; return($name); } # end-sub
"A A Jones" comes out as "A. A Jones" rather than "A. A. Jones".$name =~ s/(^| )(.)( |$)/$1$2\.$3/g;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: simpler regex
by Corion (Patriarch) on May 10, 2007 at 07:59 UTC | |
|
Re: simpler regex
by BrowserUk (Patriarch) on May 10, 2007 at 08:05 UTC | |
by johngg (Canon) on May 10, 2007 at 09:01 UTC | |
|
Re: simpler regex
by borisz (Canon) on May 10, 2007 at 07:59 UTC | |
|
Re: simpler regex
by scorpio17 (Canon) on May 10, 2007 at 13:42 UTC | |
by chrism01 (Friar) on May 11, 2007 at 01:04 UTC | |
|
Re: simpler regex
by RL (Monk) on May 10, 2007 at 09:20 UTC | |
|
Re: simpler regex
by graff (Chancellor) on May 11, 2007 at 07:12 UTC | |
by rsiedl (Friar) on May 16, 2007 at 03:36 UTC | |
by graff (Chancellor) on May 16, 2007 at 05:16 UTC |