in reply to Explaining =~ and .= operators

You'll find the answer to this in perldoc perlop

Update: Corrected 2nd example. (thanks lidden & bart)

=~ binds a scalar expression to a pattern match, eg:

print "Matches!" if "hello" =~ m/he/;
The period (.) is a concatenation operator. When used in conjunction with = it concatenates the right argument to the left argument. For example..
($foo = "hello") .= " world"; # or $foo = "hello"; $foo .= " world";
Is the same as..
$foo = "hello world";

Cheers,
Darren :)

Replies are listed 'Best First'.
Re^2: Explaining =~ and .= operators
by rinceWind (Monsignor) on Apr 04, 2006 at 10:03 UTC

    =~ can also be used in list context to obtain the list of captures: $1, $2, etc.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      Not to be overly nitpicky, but that behavior is from the m// operator, not =~. I think this distinction is important to keep in mind, because =~ can be used with m//, s/// and tr///, which all have different behaviour.

A reply falls below the community's threshold of quality. You may see it by logging in.