I have a piece of code:
$s = "<sekar kapoor>";
($name) = $s =~ /<([\S\s]*)>/;
print "$name\n"; # Output is 'sekar kapoor'
If the parentheses are removed in the second line of code like this, in the variable $name:
$name = $s =~ /<([\S\s]*)>/; # $name is now '1'
I don’t understand why it behaves like this. Can anyone please explain why it is so?
In your first example you have a list context on the left-hand side (you used parentheses); in the second you have a scalar context – you just have a scalar variable.
See the Perl docs for quote-like ops, Matching in list context: