Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

What does ".=" mean?

by anaconda_wly (Scribe)
on Apr 01, 2013 at 09:27 UTC ( #1026450=perlquestion: print w/replies, xml ) Need Help??
anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

one period and one "=". I checked perl operator table and didn't find it.

Replies are listed 'Best First'.
Re: What does ".=" mean?
by marto (Archbishop) on Apr 01, 2013 at 09:50 UTC

    . is for string concatenation (see Additive operators), = is an assignment operator.

    my $messageText = "This is some text\n"; $messageText .= "Add more text here\n";

    Is the same as:

    my $messageText = "This is some text\n"; $messageText = $messageText . "Add more text here\n";

    Update: added brackets to link, fixed typo

Re: What does ".=" mean?
by bart (Canon) on Apr 01, 2013 at 09:48 UTC
    It's one example of the generalisation of operators like +=: $x OP= $y; is the same as $x = $x OP $y;, where OP can be most of the common binary operators (meaning operators with 2 arguments, one on each side of the operator). So $x .= $y; is the same as $x = $x . $y;

    See Assignment Operators in perlop.

Re: What does ".=" mean?
by davido (Cardinal) on Apr 01, 2013 at 14:01 UTC

    perlop is only intended to be read after first reading perlintro.

    .= appends the string on the right to the contents of the scalar variable on the left.


      Thank you all. Maybe I should have thought it out.

      perlop is only intended to be read after first reading perlintro.

      Its funny but, perlop doesn't tell you to read perlintro first :)

Re: What does ".=" mean?
by perl514 (Pilgrim) on Apr 02, 2013 at 16:05 UTC

    Hi Anaconda,


    I would humbly suggest that you try out the stuff. Meaning write a small script that will use .= because thats what I did, and right after that, I tried it with a =. :). It gave me some error, but heck, thats okay. Once you do that, Then, read up the Perl Documentation, or do a google search as that will tell you why that stuff is there. Don't be afraid to try out stuff. Thats the best part of scripting...Have fun buddy :)

    I would also sincerely suggest that you look up perl documentation. You'll come across some real eye openers. One of the strengths of this beautiful language, is its awesome documentation. Use it, you'll thank yourself later.

    Perlpetually Indebted To PerlMonks

    use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books"; is a boon for Windows.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1026450]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-10-16 07:29 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (83 votes). Check out past polls.