in reply to converting strings to ints

As others have noted, it's not immediately clear that q{} == 0. Some applications might be happier to throw a fatal exception if numeric input was expected and the empty string given. Others, such as yours, would rather consider it zero. To emit a warning is a reasonable default.

As usual, when I see a contrived example, I want to ask about the real application. Contrived examples are sometimes okay but in this case, the reason for evaluating empty strings arithmetically is missing. Why was this thought necessary? How are these empty strings really being generated? What is the real significance of emptiness here (or, should I say, there)?

Without seeing the real code I can't say; but I'd hazard that if I did, I'd want to offer some advice about something other than the typecasting itself.

Replies are listed 'Best First'.
Re^2: converting strings to ints
by 7stud (Deacon) on Mar 20, 2010 at 23:47 UTC
    As usual, when I see a contrived example, I want to ask about the real application. Contrived examples are sometimes okay but in this case, the reason for evaluating empty strings arithmetically is missing. Why was this thought necessary? How are these empty strings really being generated? What is the real significance of emptiness here (or, should I say, there)?

    The situation: multiple csv files are to be combined into one file. The csv files look like this:

    itemA,,2,,4 itemB,1,,, ----- itemA,1,,, itemA,,,3,

    With the result being:

    itemA,1,2,3,4 itemB,1,,,

    In other words, there are 4 slots for numbers corresponding to each item--like an array.