What to these operators do?
Thelonius Monk
created: 2006-04-03 21:29:38
Can someone explain or point me to what these two operators' roles are? =~ .=
Re: What to these operators do?
created: 2006-04-03 21:40:12
You'll find the answer to this in [doc://perlop|perldoc perlop]

=~ 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";
Is the same as..
$foo = "hello world";

Cheers,
Darren :)

Re^2: What to these operators do?
created: 2006-04-04 01:09:04

THANK YOU!!!

Re^2: What to these operators do?
created: 2006-04-04 06:03:46

=~ 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)

Re^3: Explaining =~ and .= operators
created: 2006-04-04 12:02:22

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.

Re: What to these operators do?
created: 2006-04-04 00:42:26
In addition: perlcheat.


perlmonks.org content © perlmonks.org and Anonymous Monk, McDarren, revdiablo, rinceWind, sh1tn, Thelonius Monk

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03