Thank you. The useful note about CORE, in particular, is new to me. cts
--- On Sun, 6/24/12, Rob Dixon <[email protected]> wrote: > From: Rob Dixon <[email protected]> > Subject: Re: how to do a reference to a func in Math::Trig > To: "Perl Beginners" <[email protected]> > Cc: "Charles Smith" <[email protected]> > Date: Sunday, June 24, 2012, 11:53 AM > On 24/06/2012 19:51, Rob Dixon > wrote: > > > > or by aliasing the current package's 'sin' and 'cos' > subroutines with > > the CORE functions: > > > > use strict; > > use warnings; > > > > use Math::Trig; > > > > BEGIN { > > no warnings 'once'; > > *sin = \&CORE::sin; > > *cos = \&CORE::cos; > > } > > > > for my $func (qw/ sin cos tan /) { > > my $f = \&$func; > > print $f->(pi/4), "\n"; > > } > > > > which IMO is the tidiest, and certainly the most > efficient. > > Please note that the 'no warnings' is necessary only for > runtime typeglob assignments. This also works fine, and is > even neater. > > use strict; > use warnings; > > use Math::Trig; > > BEGIN { > *sin = \&CORE::sin; > *cos = \&CORE::cos; > } > > for my $func (qw/ sin cos tan /) { > my $f = \&$func; > print $f->(pi/4), "\n"; > } > > -- To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > http://learn.perl.org/ > > > -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
