in reply to When does '123' become the number 123.0?

A scalar is not an object, in particular it does not belong to any string or number class. In Perl, unless special measures are taken (see e.g. Simon Cozens' book "Advanced Perl programming"), not everything is an object, in contrast to e.g. Ruby.

I rather feel this is an advantage: how a scalar behaves is determined by the context in which it is used. Usually, Perl makes just the right choice and you are spared of having to enforce a special interpretation. Do you have an example of a case where a scalar was not interpreted as you expected?

  • Comment on Re: When does '123' become the number 123.0?

Replies are listed 'Best First'.
Re^2: When does '123' become the number 123.0?
by wa1ter (Initiate) on Jun 16, 2008 at 23:17 UTC
    No, not yet. My first perl program actually works as expected :) Just concerned about wasting CPU cycles, is all.

    My first exposure to OO programming was Actor, a commercial implementation of smalltalk, which I really liked a lot except for how slow it was. To add 2+2, the number 2 had to send a message to 2 telling it to add itself to 2. Ever since I've fretted about concepts like 'early binding' and useless conversions of formats inside loops and such.

    I should say I'm astonished at the speed and depth of all the replies to my newbie question and I'm very grateful to all of you. That's the best help in the shortest time I've ever seen, and I've learned good stuff from every reply. Thanks!