From jeremygwa at hotmail.com Thu Aug 7 13:56:35 2008 From: jeremygwa at hotmail.com (Jer A) Date: Thu, 7 Aug 2008 13:56:35 -0700 Subject: [VPM] passing parameters to sub ref then execute Message-ID: if this is how to exec a subroutine ref, without params .eg $o = &$c; how do I pass parameters to it. thanks in advance for your help. Jeremy A _________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From darren at darrenduncan.net Thu Aug 7 14:21:50 2008 From: darren at darrenduncan.net (Darren Duncan) Date: Thu, 07 Aug 2008 14:21:50 -0700 Subject: [VPM] passing parameters to sub ref then execute In-Reply-To: References: Message-ID: <489B676E.5030003@darrenduncan.net> Jer A wrote: > if this is how to exec a subroutine ref, without params .eg $o = &$c; > > how do I pass parameters to it. > > thanks in advance for your help. > > Jeremy A I would spell that like this: $o = &{$c}(); And then put the arguments between the parenthesis as usual. -- Darren Duncan From Peter at PSDT.com Thu Aug 7 14:26:41 2008 From: Peter at PSDT.com (Peter Scott) Date: Thu, 07 Aug 2008 14:26:41 -0700 Subject: [VPM] passing parameters to sub ref then execute In-Reply-To: <489B676E.5030003@darrenduncan.net> References: <489B676E.5030003@darrenduncan.net> Message-ID: <6.2.3.4.2.20080807142503.02d53ab0@mail.webquarry.com> At 02:21 PM 8/7/2008, Darren Duncan wrote: >Jer A wrote: >>if this is how to exec a subroutine ref, without params .eg $o = &$c; >>how do I pass parameters to it. >>thanks in advance for your help. >>Jeremy A > >I would spell that like this: > > $o = &{$c}(); > >And then put the arguments between the parenthesis as usual. I write $o = $c->(); in both cases. Either there are arguments between the parentheses or not. Preferring the arrow operator for dereferencing is a bestpractice IMHO. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ http://www.perlmedic.com/ From darren at darrenduncan.net Thu Aug 7 17:42:33 2008 From: darren at darrenduncan.net (Darren Duncan) Date: Thu, 07 Aug 2008 17:42:33 -0700 Subject: [VPM] passing parameters to sub ref then execute In-Reply-To: <6.2.3.4.2.20080807142503.02d53ab0@mail.webquarry.com> References: <489B676E.5030003@darrenduncan.net> <6.2.3.4.2.20080807142503.02d53ab0@mail.webquarry.com> Message-ID: <489B9679.5010802@darrenduncan.net> Peter Scott wrote: > At 02:21 PM 8/7/2008, Darren Duncan wrote: >> Jer A wrote: >>> if this is how to exec a subroutine ref, without params .eg $o = &$c; >>> how do I pass parameters to it. >>> thanks in advance for your help. >>> Jeremy A >> >> I would spell that like this: >> >> $o = &{$c}(); >> >> And then put the arguments between the parenthesis as usual. > > I write > > $o = $c->(); > > in both cases. Either there are arguments between the parentheses or > not. Preferring the arrow operator for dereferencing is a bestpractice > IMHO. Yes, that works too. Come to think of it, my example was derived from a somewhat different situation, when I wanted to invoke a package-qualified routine that wasn't a method. Something closer to my source example is: my $result = &{$mypkgname->can( 'myfunc' )}(...); This is for when I wanted the semantics of "MyPkg::myfunc(...)" but the name of MyPkg was in a variable. So my example was mis-applied here; when $c is already a subroutine ref, then Peter's syntax is better. -- Darren Duncan