On Sat, 28 Jul 2001, Jeff 'japhy/Marillion' Pinyan wrote:
> On Jul 28, Dan Grossman said:
>
> >#!/usr/bin/perl -w
> >use strict;
> >
> >my $funcRef = \&otherDummyFunc;
> >
> >sub callTheReferredFunc {
> > my $returnVal = &$funcRef;
> > return $returnVal;
> >}
>
> >I don't pass $funcRef to &callTheReferredFunc, and yet "-w" doesn't
> >generate a warning for an undefined reference. Are function
> >references somehow global in nature? This doesn't seem to be true of,
> >say, variable references.
>
> You're confusing something here, and I can't tell what it is.
> The variable $funcRef is NOT global -- it is lexically scoped
> (because you used my() on it). It is not visible OUTSIDE the
> scope that you declared it in -- but it IS visible inside smaller
> scopes, like the one of the callTheReferredFunc() function.
Ah, I see what my problem was. I was aware of the relevant scoping
issues but had also tried the following, which generated an error
message (whereas the previous code had not):
----------
my $dummyVar = 1;
my $varRef = \$dummyVar;
my $oneVar = &dummyFunc();
print $oneVar,"\n";
sub dummyFunc {
my $returnVal = &$varRef; # <-- note the typo
return $returnVal;
}
----------
I was trying to figure out what the heck the difference is between a
reference to a function and a reference to a variable that would cause
Perl to like one but not the other when accessed inside the function.
Of course, I had meant to type "$$varRef" inside the function, rather
than "&$varRef" ...
Thanks,
Daniel
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]