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

Re: [FWP] Regex to remove whitespace and to capitalize



On Fri, Jan 07, 2000 at 11:04:59AM -0500, Steve Lane wrote:
> Tim Ayers wrote:
> > So I tried
> > 
> >   $x =~ s/(^.)|[\s_]+(\S)/\U\1/g;
> > 
> > but that didn't work. For example, 'Hi there' goes to 'Hihere'. I was
> > surprised by the loss of the 't'. I would have more expected
> > 'HiHhere'. What's going on?
> 
> in the second substitution, ' t' matches '[\s_]+(\S)',
> and $2 (-not- $1) gets set to 't'.  $1 is ''.  that's
> what happened to the 't'.

To be precise, $1 is undef, because that part of the regular expression was
not matched at all.

Ronald

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