in reply to Re^2: Avoiding silly programming mistakes
in thread Avoiding silly programming mistakes
Probably why I have never adopted it. That doesn't mean that there aren't people out there recommending it. For those following along at home, perl doesn't always issue a warning with the assignment operator in a conditional:
#!/usr/bin/perl use strict; use warnings; if (my $foo = foo()) { print "No warning\n"; } if (my @asdf = (1..5)) { print "No warning here either\n"; } if (my $bar = {one => 1}) { print "Look Ma, no warning\n"; } while (my $rec = <DATA>) { # ... } sub foo { return 42; }
Of these, the only suspect one is the first and perl assumes you know what you are doing. Writing it with the operands reversed would have generated an error (assuming no lvalue attributes) but I agree, this is a stretch.
You have re-inforced my two points. A lesson learned the hard way is learned best and there is no substitute for experience but figuring out how much of other's experience to rely on is tricky.
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Avoiding silly programming mistakes
by moritz (Cardinal) on Aug 20, 2008 at 14:04 UTC | |
|
Re^4: Avoiding silly programming mistakes
by JavaFan (Canon) on Aug 20, 2008 at 14:11 UTC | |
by Limbic~Region (Chancellor) on Aug 20, 2008 at 14:48 UTC |