Thank much Jenda. The last but not least OTOH thing below clarifies everything.

Cheers~

  Regards & Thanks 


--- On Wed, 12/3/08, Jenda Krynicky <[EMAIL PROTECTED]> wrote:

> From: Jenda Krynicky <[EMAIL PROTECTED]>
> Subject: Re: query on dynamic
> To: [email protected]
> Date: Wednesday, December 3, 2008, 4:38 PM
> From:                 p sena <[EMAIL PROTECTED]>
> > Could someone pls explain me behind the hood thing for
> --
> > $x = "041"
> > $y = 12
> > then $z = $x + $y, how this comes to be numeric
> addition. 
> 
> In Perl + is always numeric addition. Always. No matter
> what the 
> operands are. As such it first evaluated both operand in
> numeric 
> scalar context.
> 
> > This will
> > also be seen for any number of those initial zeros in
> $x and may also
> > exist in similar way in $y too. I believe this comes
> for dynamic
> > languages prop ? If this is so then can one do
> arithmetic(inclusive of
> > comparison tests) freely on such situations, without
> taking into
> > concern whether the $x (for example) above comes with
> zero perpended
> > (for cases of digits from 0-9) or is a two digit
> number itself (like
> > numbers > 10) ? I mean I can do 04 + 12, 00104 +
> 01, 0101 + 2.50,
> > 044.25 + 02.50 etc.. 
> 
> Likewise > is always numeric comparison. Always. If you
> want a string 
> comparison you need to use gt.
> 
> Some languages, even dynamic-typed ones, use + for both
> addition and  
> concatenation and < or > for both numeric and string
> comparison and 
> choose the right operation based on the types of the
> values. Which 
> often leads to hard to find bugs. Like for example
> 
>    document.frm.fld.value += 1;
> 
> What would you expect it does? Increment the value? Nope.
> It appends 
> "1" to the value! Disambiguating numeric and
> string operation is yet 
> another thing that Perl does right.
> 
> OTOH, be careful with the leading zeroes! 
>   "074" == 74
>    074  != 74
> 
> The catch is that a numeric literal starting with zero (not
> folowed 
> by 'x') is assumed to be octal, not decimal. So 074
> is 7*8+4 not 
> 7*10+4. "074" is not a numeric literal, it's
> a string literal. But if 
> you evaluate a string in numeric context then Perl takes
> everything 
> that looks like a decimal number at the start of the string
> (skipping 
> any whitespace). 
> 
> Jenda
> ===== [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
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe:
> http://listserv.ActiveState.com/mailman/mysubs


      

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to