in reply to Split ( ) is Giving Me a Splitting Headache
In addition to the good answers you already got, which I recommend you to read carefully to understand what's going on, you can get what you want with a syntax similar to yours with a slight abuse of map:
my @Parts = map split, $Phrase;
I recommend that you do not cargo-cult this usage though, and postpone adopting it to when you will understand exactly what's going on in it too. Also because this doesn't really buy you anything that split basic usage as in rhesa's example won't.
While we're there, one more warning: you must have noticed that people here suggested using a string contining a single space as a first argument. Notice that this is a special case, which is supposed to what you want - because it's in fact what often people want, which in turn is the reason why it's the default. But in general split expects a proper pattern as a first argument. If you give it a string, then it will be automatically converted. It is generally recommended that you use a real pattern instead.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Split ( ) is Giving Me a Splitting Headache
by dsheroh (Monsignor) on May 24, 2006 at 15:01 UTC | |
by blazar (Canon) on May 25, 2006 at 11:01 UTC |