note
johngg
Another place where the effect of <code>my $x;</code> and <code>my ($x);</code> differs is in matching regular expressions. Assigning a match in scalar context just records whether the match was successful, like this<p>
<code>
perl -e 'my $x = "abcdefg" =~ /(cd)/; print "$x\n";'</code><p>
prints<p>
<code>1</code><p>
whereas matching in list context assigns the captures in the match<p>
<code>
perl -e 'my ($x) = "abcdefg" =~ /(cd)/; print "$x\n";'</code><p>
prints<p>
<code>cd</code><p>
Normally, or rather probably, you would be making more than one capture in the regular expression so you would do something like<p>
<code>
my($this, $that) = $string =~ /abc(def).+?(pq)$/;</code><p>
Cheers,<p>JohnGG
541132
541132