addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [perl-108] AUTOLOAD and late binding? match vars? params

From: Andy B.
Sent on: Friday, July 25, 2014 11:28 AM

On Thu, Jul 24, 2014 at 5:48 PM, Graham Knop <[address removed]> wrote:
The first is that regex match variables are implicitly localized to
where the match is done.  You can take advantage of this by wrapping
the matching you do on $AUTOLOAD in a block

I didn't know about "implicit localization" that's slick.  I thought if the sub block itself wasn't enough to localize the match vars, an explicit
local($1, $2);

would be needed.  That does work too.  It seems to "un-alias" the $1 and @_ while using a bare block swaps the value of @_ inside the block, but it returns to the original content afterwards.  A very subtle bunch of lexicalness there ;->

My original fix was to use split instead of captures:
my ($space, $func) = split(/::/, $func);

A lesson too, in thinking about how the code might be called as to unexpected side-effects.  Maybe I should always localize/block any captures in a library routine ... nah!




Andy Bach,
[address removed]
[masked] cell
[masked] wk

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy