in reply to Re^4: Curious result of using "my ... if ..."
in thread Curious result of using "my ... if ..."
I don't see why this should be an error. Just as
my $x = 5 if $t;could be semantically equivalent to
my $x; $x = 5 if $t;
I think it all boils down to a matter of personal interpretation and taste; your example doesn't convince me at all: yes, it could, but I see no reason why it should. More precisely, it's true that the single
my $x = 5;
statement is semantically equivalent to the two
my $x; $x = 5;
statements. But is it true in general than when STATEMENT is equivalent to STATEMENT1; STATEMENT2; ... STATEMENTn; then also
STATEMENT if condition;
is equivalent to
STATEMENT1; STATEMENT2; ... STATEMENTn if condition; # ?!?
IMHO not only is the answer no but FWIW I see no aesthetical appeal of such an "algebraic" property.
OTOH since
STATEMENT if condition;
is generally equivalent to
if (condition) { STATEMENT }
and
if ($t) { my $x = 5 }
is perfectly valid, albeit fundamentally useless, perhaps the "incriminated" construct should not trigger an error, but just be a happily useless thingy. Granted, Perl 5 already has so many ad hoc deviations from orthogonality for the sake of beauty, pragmatics and magic that one may want to throw in yet another one: yet I still fail to see how that particular construct could be of any good with any of those.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Curious result of using "my ... if ..."
by jdporter (Paladin) on May 16, 2007 at 16:06 UTC | |
by blazar (Canon) on May 16, 2007 at 19:06 UTC |