From: Rob Dixon <[EMAIL PROTECTED]>
> 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
> 
> All they're saying is that $a = $b doesn't tie $a and $b together in any way,
> it just copies the value of $b to $a. If you change $b after that it won't
> alter $a again.

Unless of course the $b was a reference. In that case changing the $b 
will not affect $a and changing $a will not affect $b, BUT changing 
the something referenced by $a will change the thing referenced by $b 
... because it's the same something:

@array = (1,3,7);

$b = [EMAIL PROTECTED];
$a = $b;

print "[EMAIL PROTECTED], [EMAIL PROTECTED]";

$a->[1] = 99;
print "[EMAIL PROTECTED], [EMAIL PROTECTED]";

$b->[2] = -1;
print "[EMAIL PROTECTED], [EMAIL PROTECTED]";

$a = [1,2,3];
print "[EMAIL PROTECTED], [EMAIL PROTECTED]";


Another thing that I think should be included in that document is 
that Perl, unlike C, uses different operators for numerical and 
string comparisons:

   1  < 5
   10 > 5

   1  lt 5
   10 lt 5
   'hello' gt 'ciao'

The numerical operators are <, >, <=, >=, ==, !=
The string operators are lt, gt, le, ge, eq, ne

HTH, Jenda
P.S.: Please do not use $a and $b variables except in the sort{block} 
in real scripts. The variables are a bit special and the names are 
definitely not too descriptive :-)

===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


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


Reply via email to