[comp.lang.perl] Does it have to be like this?

ccount@athena.mit.edu (Craig A Counterman) (10/12/90)

010 < 10.  I can deal.
010.0 > 10.  This bugs me.

(Patchlevel 28)

I know what's happening, I hope it can be changed.  It's just too obscure.

The annoying thing is that I discovered this when discussing a C
compiler's annoying failure to deal with '-08.123'.  I wanted to show
him how a _good_ language would handle it.  Oh boy.

Oh, and:

$x = 010.;

is a syntax error.

just so you know,
Craig

PS:  To explain for the the confused: a leading 0 on an integer
indicates that the number is in octal, e.g. '077'.  When perl 3.0/28
sees '010', it's taken to be 8 so (010 < 10).  Ok, so far so bad.  But
(correct me if I'm wrong, Larry) 010.0 is parsed as the numbers 8 and
0, with the '.'  indicating a string concatenation, so 010.0 is 80 and
(010.0 > 10).  Now, as an exercise, explain why
010.0 - 010.0000 == 720

Oh boy.

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (10/13/90)

In article <1990Oct12.060936.7501@athena.mit.edu> ccount@athena.mit.edu (Craig A Counterman) writes:
: 010 < 10.  I can deal.
: 010.0 > 10.  This bugs me.
: 
: (Patchlevel 28)
: 
: I know what's happening, I hope it can be changed.  It's just too obscure.
: 
: The annoying thing is that I discovered this when discussing a C
: compiler's annoying failure to deal with '-08.123'.  I wanted to show
: him how a _good_ language would handle it.  Oh boy.

You want a "good" language, don't look here.  Perl is pathologically eclectic,
and like Unix itself, generally gives you enough rope to hang yourself.
Other than the fact that it almost always does what you want, it's a lousy
language.  I'm not a language designer.  I'm just a squeaky-wheel greaser.

: Oh, and:
: 
: $x = 010.;
: 
: is a syntax error.
: 
: just so you know,
: Craig
: 
: PS:  To explain for the the confused: a leading 0 on an integer
: indicates that the number is in octal, e.g. '077'.  When perl 3.0/28
: sees '010', it's taken to be 8 so (010 < 10).  Ok, so far so bad.  But
: (correct me if I'm wrong, Larry) 010.0 is parsed as the numbers 8 and
: 0, with the '.'  indicating a string concatenation, so 010.0 is 80 and
: (010.0 > 10).

That's correct.

: Now, as an exercise, explain why 010.0 - 010.0000 == 720

Hint: "." and "-" are both left associative and have the same precedence.

: Oh boy.

Right.  I suppose I should point out that you're the first person to point
this out.  Obviously not a major malfunction...

It might be worth a warning with -w though.

Larry

eastick@me.utoronto.ca (Doug Eastick) (10/13/90)

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>: $x = 010.;
>: is a syntax error.
>: 
>: PS:  To explain for the the confused: a leading 0 on an integer
>: indicates that the number is in octal, e.g. '077'.  When perl 3.0/28
>: sees '010', it's taken to be 8 so (010 < 10).  Ok, so far so bad.  But
>: (correct me if I'm wrong, Larry) 010.0 is parsed as the numbers 8 and
>: 0, with the '.'  indicating a string concatenation, so 010.0 is 80 and
>: (010.0 > 10).

>Right.  I suppose I should point out that you're the first person to point
>this out.  Obviously not a major malfunction...

Hey, other perl users:  do you sometimes shake your head REAL fast
after reading stuff like this?  But I guess thats why perl is so damn
interesting.

>Larry

I've meant to say this for a long time.  Larry, you're warped.  But
it's a good kind of warped, if you know what I mean.  Keep up the
confusing work and one-line answers (I especially liked the one-liner
to the XXencode subject).

...now if I could only get 3.0/28 to work on IRIX 3.3.0.

ccount@athena.mit.edu (Craig A Counterman) (10/13/90)

OK, so it does have to be like this :-)

In article <9951@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
>In article <1990Oct12.060936.7501@athena.mit.edu> ccount@athena.mit.edu (Craig A Counterman) writes:
>: 010 < 10.  I can deal.
>: 010.0 > 10.  This bugs me.

Actually, I later decided it didn't bug me _that_ much.

> ...

>You want a "good" language, don't look here.  Perl is pathologically eclectic,
>and like Unix itself, generally gives you enough rope to hang yourself.
>Other than the fact that it almost always does what you want, it's a lousy
>language.  I'm not a language designer.  I'm just a squeaky-wheel greaser.

Well, I _still_ consider it a good language, it's saved me lots of
time already.  I promote it at every opportunity I get.  I just was
surprised by this behaviour.

>
>Right.  I suppose I should point out that you're the first person to point
>this out.  Obviously not a major malfunction...

True enough.

>
>It might be worth a warning with -w though.

Yes, please.  Leading zeros occasionally occur in tabulated numbers,
and if one converts the table to an array, through simple string
manipulation, one may end up with +013.0512, which is a problem (in C
and perl).  Actually, in perl you're still safe as long as you quote
it, "+013.0123", so perl does beat C after all.

I think 010.0 - 010.0000 yielding 720 is the wierdest perl thing I
haven't seen in a JAPH.  After after The Book comes out, there should
be a 'perl puzzle book'.  Perhaps it could be a companion volume to
the 'book of perl poems' :-).

>
>Larry

Thanks,
Craig

kpc00@JUTS.ccc.amdahl.com (kpc) (10/16/90)

Antedisclaimer: I have neither perl (Larry Wall, do we have email
contact?) nor perl documentation.

   >: 010 < 10.  I can deal.
   >: 010.0 > 10.  This bugs me.

   Actually, I later decided it didn't bug me _that_ much.

I assume that without the leading '0' it works OK?  -- that only
decimally expressed numbers can be floating point?

Thanks.  I look forward to trying perl.

--
If you do not receive a reply from me, please resend your mail;
occasionally this site's mail gets delayed.

Neither representing any company nor, necessarily, myself.