<?xml version="1.0" encoding="windows-1252"?>
<node id="541140" title="Re: my $x or my ($x)" created="2006-04-04 08:47:57" updated="2006-04-04 04:47:57">
<type id="11">
note</type>
<author id="401112">
johngg</author>
<data>
<field name="doctext">
Another place where the effect of &lt;code&gt;my $x;&lt;/code&gt; and &lt;code&gt;my ($x);&lt;/code&gt; differs is in matching regular expressions. Assigning a match in scalar context just records whether the match was successful, like this&lt;p&gt;
&lt;code&gt;
perl -e 'my $x = "abcdefg" =~ /(cd)/; print "$x\n";'&lt;/code&gt;&lt;p&gt;
prints&lt;p&gt;
&lt;code&gt;1&lt;/code&gt;&lt;p&gt;
whereas matching in list context assigns the captures in the  match&lt;p&gt;
&lt;code&gt;
perl -e 'my ($x) = "abcdefg" =~ /(cd)/; print "$x\n";'&lt;/code&gt;&lt;p&gt;
prints&lt;p&gt;
&lt;code&gt;cd&lt;/code&gt;&lt;p&gt;
Normally, or rather probably, you would be making more than one capture in the regular expression so you would do something like&lt;p&gt;
&lt;code&gt;
my($this, $that) = $string =~ /abc(def).+?(pq)$/;&lt;/code&gt;&lt;p&gt;
Cheers,&lt;p&gt;JohnGG</field>
<field name="root_node">
541132</field>
<field name="parent_node">
541132</field>
</data>
</node>
