[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] Dumb Questions
> Concerning scope...
>
> I'm confused about this:
>
> my($iR, $iC, $oWkS, $oWkC);
>
> foreach my $oWkS (@{$oBook->{Worksheet}}) {
> for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} &&
> $iR <= $oWkS->{MaxRow} ; $iR++) {
>
> ... blah ...
>
>
> If I understand this correctly, $iR gets created prior to
> entering the loop, and then gets ignored by the redefinition
> in the for loop. So, does this:
>
> my($iR, $iC, $oWkS, $oWkC);
>
> foreach $oWkS (@{$oBook->{Worksheet}}) {
> for($iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} &&
> $iR <= $oWkS->{MaxRow} ; $iR++) {
>
> ... blah ...
>
>
> do essentially the same thing, except not redefine, or is
> there a reason it's defined twice?
If $iR is not used anywhere after the foreach block, then you are exactly right.
I think Perl "warnings" would bark at the original, warning about the (probably accidental) re-scoping of $iR.
You should always use warnings*.
perl -w scriptname.pl
or
#!/usr/bin/perl -w
or
use warnings;
HTH,
j
* obligatory ubiquitous recommendation