in reply to Re: I've been bit in the neck by open()
in thread I've been bit in the neck by open()

allows you to do my $var; $var += 3; without warning as well.

That's interesting. I would have figured it would warn of an uninitialized variable.

This was all I could find:
Use of uninitialized value%s (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo , and the warning will refer to the concatenation (.) operator, even though there is no . in your program.


What is the reasoning behind this?

Replies are listed 'Best First'.
Re^3: I've been bit in the neck by open()
by dragonchild (Archbishop) on Feb 16, 2005 at 13:27 UTC
    sub unique { my %seen; $seen{$_}++ for @_; keys %seen; } my @unique_values = unique( @some_values );

    While it's not the best or most efficient way, it is the standard way to extract the unique elements from an array. Do you really want N "uninitialized variable" warnings where N is the number of unique elements in your array?

    And, that's just one common usage.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      To be honest, yes, if I've requested warnings.

      But this is probably just a philosophical divide. I often get mixed feelings about languages that require initialization versus assumptions. One day I like one, the other day I like another :-D

      I assume there's some measure of consistency, though. I guess what I'm really wondering is - where is that line?
        I assume there's some measure of consistency, though. I guess what I'm really wondering is -where is that line?

        Where Larry told it to be. :-) (Plus, consistency is the hobgoblin of foolish minds, or something like that.)

        I'm not being facetious - this is just one of those nooks and crannies of Perl5 that you either know or you don't. Perl6 (supposedly) will be more consistent, but Perl5 isn't. *shrugs*

        Or, rather, it's very consistent, for some definition of consistent. (Probably not the Webster's definition, though ... remember - it's not messy, it's in a state of creative flux!)

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      While it's not the best or most efficient way, it is the standard way to extract the unique elements from an array. Do you really want N "uninitialized variable" warnings where N is the number of unique elements in your array?

      And, that's just one common usage.

      I know you're not answering to me, but to another monk. However that "that's just one common usage" thing seems to me to be a reminiscence of my original post, in which case I'd like to point out that I've noticed it's been misunderstood, well at least about that cmt about a warning, that is. I already posted a reply in which I hopefully explain better what I really meant...
Re^3: I've been bit in the neck by open()
by Anonymous Monk on Feb 16, 2005 at 14:54 UTC
    What is the reasoning behind this?

    Programmer convenience. Remember that Perl is there to serve the programmer - not the other way around. Anytime you have to do something for the sole reason of not triggering a warning, you've not been productive. Warnings should not get in the way - the more warnings there are that give false positives, the more likely it is warnings are ignored, or shut off completely. (As any security or ergonomics expert can tell). Wanting to do += (or .=) on undefined values is common enough to not have a warning emitted. Beside the example given, here's another:

    $sum += $_ for @list;
    Note that Perl is smart enough to figure out that having undefined values for *= or /= is probably a mistake, and it warns then.