Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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.

Comment on What does ".=" mean?
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 marto (Bishop) 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 davido (Archbishop) 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.


    Dave

      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";
    http://dwimperl.com/windows.html is a boon for Windows.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (16)
As of 2014-12-22 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (128 votes), past polls