For unrelated reasons*, I don't like working at the global level. This has the side-effect of avoiding the issue.
#!/usr/bin/perl -w { my ( $length, $breadth, $height ) = ( 10, 20, 30 ); my $volume = calc_volume( $length, $breadth, $height ); print "\nvolume = $volume\n"; } sub calc_volume { my ( $length, $breadth, $height ) = @_; my $volume = $length * $breadth * $height; return $volume; }
While the snippet you provided has two variables with the same name in scope at the same time, the snippet I provided does not.
* — First, it makes the scope of variables much larger than it needs to be. Secondly, global objects are destroyed in an unpredictable order. That means a child object can be reaped before its owners is, which is bad if you have a custom destructor.
In reply to Re: Confusion in naming variables in subroutines
by ikegami
in thread Confusion in naming variables in subroutines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |