[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] TPJ One-Liner #39



Ronald J Kimball wrote:
> How could the following one-liner (#39) from the latest Perl journal be
> improved?
>
> perl -ne 'push@w,/(\b[A-Z]\S*?\b)/g;END{print"@w"}'

First of all I don't really care for [A-Z]-like constructs. They don't
localize all that well :-) But since we lack a better way to get a match for
an upper case character...

My first idea for improvement was of course a simple;

> perl -ne 'print /(\b[A-Z]\S*?\b)/g'
> 
It gets rid of the array, but it misses out on the spaces between the words.
A way to remove the array and get the correct spacing would be;

perl -e '$/="";$,=" ";print <STDIN>=~/(\b[A-Z]\S*?\b)/g"

Now, if this is an improvement or not... :-)


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe