On May 31, Paul said:

>> my @chars = $string =~ /\S/g;
>
>I've seen a couple of people doing this, and maybe I'm just confused,
>but....
>
>Isn't the point of the original request to split into the original
>characters, but leave *out* the spaces?
>
>and isn't \S any nonspace?
>
>So, if you split on \S, won't it give you just the strings of
>whitespace as the elements returned?

Well, sure, if you split() on \S.

  @ws = split /\S/, $string;

But we're not split()ing.  We're matching all non-spaces.

  my @non_ws = $string =~ /(\S)/g;

Or, since a global pattern match in list context without ()'s will return
the entire match:

  my @non_ws = $string =~ /\S/g;

This will be an example in my book.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **


Reply via email to