in reply to Re^3: Unforgettable Closures? (shave)
in thread Unforgettable Closures?

(shave)
hehe. Yeah, Occams Razor because of my mistaken assumptions (closure funkiness versus perlsyn (my) funkiness). Me:
Thanks, that clears it up, I guess. I've not got anything newer than Perl 5.8.8, and grepping perlsyn for the said gotcha finds nothing, so I'm assuming I need a newer Perl?
I meant new version of Perl for which the man page for perlsyn mentions the "my" strangeness. I ought to have mentioned it, but before I'd reproduced the funkiness on my local 5.8.8 installation, I came across it on (sigh) 5.6.1 - on which the following fix worked:
Well whatever the reason is, the fix was simply:
#my $func = shift if ref $_[0] eq 'CODE'; my $func = ref $_[0] eq 'CODE' ? shift() : undef;
Of course, as you rightly point out, separating the "my" and the conditional also works, like you point out.
my $func; $func = shift if ref $_[0] eq 'CODE';
all good! Thanks.

Replies are listed 'Best First'.
Re^5: Unforgettable Closures? (shave)
by ikegami (Patriarch) on Dec 10, 2007 at 05:59 UTC

    I meant new version of Perl for which the man page for perlsyn mentions the "my" strangeness.

    The warning has been in perlsyn since 5.8.1.

    I've not got anything newer than Perl 5.8.8, and grepping perlsyn for the said gotcha finds nothing,

    It's there. Look at "NOTE:" at the end of the "Statement Modifiers" section.

      It's there. Look at "NOTE:" at the end of the "Statement Modifiers" section.
      Whoops, my bad. I'd been grepping for 'behavior' instead of 'behaviour' ... ;-). It's there indeed. Many apologies!
Re^5: Unforgettable Closures? (shave)
by tye (Sage) on Dec 10, 2007 at 05:52 UTC

    [doc://perlsyn] goes to perlsyn which currently claims to be 5.8.8 vintage and says:

    NOTE: The behaviour of a my statement modified with a statement modifier conditional or loop construct (e.g. my $x if ... ) is undefined. [etc.]

    In case that helps you in future searches or something. Perhaps the highlighting tripped up your grep or something? :)

    Update: DYK you can type "doc://perlsyn" in the 'Search' box found at the top of most PerlMonks pages and be taken to the same place as [doc://perlsyn] ? FYI. I use that feature all the time. [ For example, type "abbr://dyk" if that abbr. isn't familiar or type "abbr://fyi" to see a bunch of expansions that don't match what I meant (and one that did) :]

    - tye