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

Re: [FWP] TPJ One-Liner #39



> 
> trowton@broadcast.com  wrote;
> >--(albeit with an extra white space at the end);
> >--perl -ne'$,=$";print/(\b[A-Z]\w*)/g,""'
> >
> >Couldn't you just 'chomp' it? 
> >Or am I missing something? 
> 
> First: Chomp only removes characters corrensponding to the current value of
> $/. Which defaults to newline. So it wouldn't remove the extra space. Unless
> you modified $/, which would add "lots" of code.
> 
> Second: You can't chomp the pattern match. You get this error message;
> Can't modify pattern match in safe chop at -e line 1, at end of line
> 
> Third: You only want to strip the final white space on the last iteration,
> not each and every pass. Once again you'd need extra code.
> 
> I'm quite sure it can be solved, but at the price of code bloat! :-)

You can fix that pesky final character with a mere 16 characters of 
bloat (~ 40%), and a rewrite: 

perl -ne'push(@a,/\b[A-Z]\w*/g);END{print join($",@a)}'

Fun anyone?

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