These two do the same thing:
my $x; my ( $x );
The second one is easier to add more variables to later. These are the same:
my $x ; my $y; my ( $x, $y ); # NOT: my $x, $y
These two are a little different:
my $x = foo(); my ( $x ) = foo();
The difference between them is that the second puts foo() in a list context while the first puts foo() in a scalar context.
In this particular case (my ($x) = $y =~ /(p)/), the list context is important because that's how the captures come back. In a scalar context, you'd just get a boolean value to tell you whether the pattern matched.
In reply to Re^4: Str extract the word between the first and the 2nd '|' character
by kyle
in thread Str extract the word between the first and the 2nd '|' character
by dani_cv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |