in reply to Perl Warnings...
Is this really *that* bad? If so why?
Short version: I think it's clear that
is undesirable, and I think that the warnings are more to prevent this sort of behaviour than your innocuous example.my $x = 'string'; my $x = 17;
Long version: It's nice to have some imperative semblance of referential transparency—when I see a variable, I like to know what it means (even if I can't quite translate
tomy $x = 5; $x += 1; print $x;
). If you use my twice, you're explicitly saying “This isn't close enough to the old variable that I can view the re-assignment as updating; I want to view it as an entirely new variable.” Thus, if I'm skimming the code, I have to keep careful track of declarations to be able to tell whether a given occurrence of $query refers to the original kind of query, or the new one.my $x = 5; $x += 1; print 5;
|
|---|