Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • by dstar (8812) on 2008.09.05 5:54 (#64762)

    I think your complaint boils down to "Ruby doesn't have 'use strict;'", combined with "Ruby can't tell the difference between a local variable and a method call". The perl 5 code that's actually equivalent to the ruby code is

    sub y {
        if false { $x = 100 }
        return $x;

    -- Note the lack of 'my' in the method; this would 'work' if use strict wasn't in effect, assuming of course that $x didn't exist elsewhere in the program. A call to y would return undef unless the program had assigned to $x anywhere else -- which is a) probably not what you expect and b) the reason every perl program I write starts with 'use strict'.

    Ruby doesn't have _that_ problem, but it has the probably more confusing problem you pointed out (and I'm glad I know that now, as I've never run into that issue, and I would never have figured it out if I didn't already know it); the idea that referencing a variable _in a branch that's not taken_ causes it to spring into existence is counter-intuitive at best (enough so, in fact, that I'm wondering whether that's intentional, or a bug in ruby, now that I know about it...).

    The second complaint is a feature, not a bug; it was a deliberate design decision, as I understand it.