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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to