It may be easier to understand outside of computer context and delving
into pointers/references/memory addresses.  I'm sure there are some good
tried and true analogies that I can't think of so I'll try to come of up
with one that fits well into computers without getting too far from
reality or too esoteric an aspect of reality (ans still relatively flat
so it's closer to a scalar than a class).

    Suppose you are counting coins and placing them in containers that
you use for specific uses...one for laundry ($laundry_tin) and one for
toll charges ($toll_tin).  You start off with 10 dollars (or currency of
your choice) and divide it evenly, so now $laundry_tin = 5.00 and
$toll_tin = $laundry_tin.  You assigned the _value_ of one to the other
so they both contain 5.00, but they both contain their own 5.00 of
coins.  A couple days later you do a load of laundry and $laundry_tin is
down to 4.50.  $toll_tin is still at 5.00 (you didn't touch that tin so
it wouldn't change). You could make them equal again, assign them equal
but it doesn't happen automatically.

    Now to extend this for the concept's sake (though the bit above is
the important part for your question).  Suppose that you realize that
you aren't paying that many tolls so you decide to share that money
between tolls and snacks.  You could assign $snack_tin to $toll_tin by
_reference_ which would mean that $snack_tin and $toll_tin are the same
tin, sharing the same set of money.  If you take out money for snacks,
you lose the money for tolls (so you can't fill your face if you need to
go somewhere).  They are different names to access the amount of change
(value) in the same tin (address). 

The note is saying that Perl does scalar assignment the first way unless
you tell it otherwise.  $a = $b doesn't mean that $a is the same as $b,
it means it gets the value of $b.  If you want to tell it otherwise
"perldoc perlreftut" would probably be the place to start. 



Kaushal Shriyan wrote:
> Hi,
>
> I am referring to http://www.gnulamp.com/perlscalars.html
>
> $a = $b; # Assign $b to $a
>
> Note that when Perl assigns a value with *$a = $b* it makes a copy of $b and
> then assigns that to $a. Therefore the next time you change $b it will not
> alter $a.
>
> I did not understand the Note:- Can some one make me understand this
> statement with examples
>
> and also what i understand from the below statements( I have added in the
> comments), is it correct.
>
> $a += $b;   #is it $a = $a + $b;
> $a -= $b;    #is it $a = $a - $b;
> $a .= $b;    #is it $a = $a . $b;
>
> Thanks again
>
> Thanks and Regards
>
> Kaushal
>
>   


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to