in reply to Explanation of warning created when over using "my"
Simply put, you may be overwriting a variable that don't want to.
Consider:
use strict; use warnings; my $x = very_important_number_calculation(); printf "Your very important value is $x\n"; # time passes ... my $x = temporary_value(); my $y = temporary_value(); printf "(x + y) = ($x + $y) = ", $x + $y; # more time passes ... print "Your very important number calculation yielded: $x\n";
See how that could ruin your day if you weren't warned about it?
There's a simple solution if you're sure you want to reuse the variable, though. Just do it, but omit the my after the first time:
#!/usr/bin/perl use strict; use warnings; my $pet = 'dog'; $pet = 'cat'; $pet = 'ferret';
And I wouldn't call that "bad programming practice". It's clear that you're intentionally resetting the variable to different values, and there's nothing (inherently) wrong with that.
|
|---|