Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.= operator 1

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
just wondering what the .= operator does

I have seen it used like this:

$some_string .= 'text'
Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
theEclipse,

It's shorthand for concatenation. For example:

Code:
if ( &something ) {
   $foo = $foo . 'bar';
}

Can be written as:

Code:
if ( &foo() ) {
   $foo .=  'bar';
}

In my stuff, I tend to use it for creating lists, such as errors detected in online forms.

For more information, please see
Code:
perldoc perlop
and search for "Assignment Operators".

Hope this helps...

-- Lance
 
another typical example.....

while(<HANDLE>) { $handle_contents .= $_; } 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
so what is concatenation?

is that just adding a string? Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Exactly
Code:
$name = &quot;Fred&quot;;

$foo  = &quot;Hello&quot;;
$foo .= &quot;there &quot;;
$foo .= $name;

print &quot;$foo\n&quot;;

Returns: Hello there Fred
Cheers, Neil
 
ok. let me understand this:

if you look at your post carefully, it would really return:

Hellothere Fred

Right? Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Correct. There is no space between Hello and there when this is placed into the variable $foo.
 
[rofl2] Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top