<?xml version="1.0" encoding="windows-1252"?>
<node id="592036" title="Re: Understanding Split and Join" created="2006-12-28 08:23:26" updated="2006-12-28 03:23:26">
<type id="11">
note</type>
<author id="540414">
jwkrahn</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;

There are cases where it is equally easy to use a regexp in list context to split a string as it is to use the split function. Consider the following examples:

&lt;c&gt;
my @list = split /\s+/, $string;
my @list = $string =~ /(\S+)/g;
&lt;/c&gt;

In the first example you're defining what to throw away. In the second, you're defining what to keep. But you're getting the same results. That is a case where it's equally easy to use either syntax. 

&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
In your regexp example you don't need the parentheses, it will work the same without them.
&lt;/p&gt;
&lt;p&gt;
If &lt;b&gt;&lt;c&gt;$string&lt;/c&gt;&lt;/b&gt; contains leading whitespace then you will &lt;b&gt;NOT&lt;/b&gt; get the same results.  To demonstrate examples that produce the same results:

&lt;c&gt;
my @list = split ' ', $string;
my @list = $string =~ /\S+/g;
&lt;/c&gt;

</field>
<field name="root_node">
591988</field>
<field name="parent_node">
591988</field>
</data>
</node>
