in reply to Re^3: Str extract the word between the first and the 2nd '|' character
in thread Str extract the word between the first and the 2nd '|' character
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.
|
|---|