Jeff Pinyan <[EMAIL PROTECTED]> writes:

> On May 31, Pedro A Reche Gallardo said:
> 
> >How can I split  a  string of caracters -any but blank spaces-   into
> >the individual caracters?
> 
> So you want to split "what's up, doc?" into
> 
>   @chars = qw( w h a t ' s u p , d o c ? );
> 
> That is, every character except spaces?
> 
> First, remove spaces from the string:
> 
>   $string =~ tr/\n\r\f\t //d;  # translate whitespace to nothing
> 
> Then, split the string into characters:
> 
>   @chars = split //, $string;

Or, you could do it in one step:

@chars = split /\s*/, $string;

Which splits on any number (including zero) of whitespace characters,
throwing away the characters that match.

-- 
Piers Cawley
www.iterative-software.com

Reply via email to