POSIX and Math::Trig

A

Andre Majorel

Is there a simple way to use both POSIX and Math::Trig without
getting a flurry of warnings ?

Subroutine main::atan redefined at myscript line 24
Subroutine main::asin redefined at myscript line 24
Subroutine main::tanh redefined at myscript line 24
Subroutine main::cosh redefined at myscript line 24
Subroutine main::tan redefined at myscript line 24
Subroutine main::acos redefined at myscript line 24
Subroutine main::sinh redefined at myscript line 24

Thanks in advance.
 
P

Peter Makholm

Andre Majorel said:
Is there a simple way to use both POSIX and Math::Trig without
getting a flurry of warnings ?

If both modules are well-behaved you should be able to just import the
sumbols you need from each module. That is doing something like:

use POSIX qw(chmod chown);
use Math::Trig qw(tan cos sin);

If you need to handle file ownershipå and permissions and use the
basic triogometric functions from Math::Trig

//Makholm
 
A

Andre Majorel

Just import the subs you want from POSIX, rather than all of them
(assuming the Math::Trig version is the version you want).

Thanks folks. My script evals its arguments so which subs are
needed is not known at write time.

I was hoping there was a way of saying "use X and quietly
redefine whatever you want", or "use X but don't redefine
anything". Or, at worst, "use X and import everything except
this and that".
 
J

Jürgen Exner

Andre Majorel said:
Thanks folks. My script evals its arguments so which subs are
needed is not known at write time.

But you should know at development time _which_ version of e.g. cosh,
tanh, or tan you want to use when needed, the one from POSIX or the one
from Math::Trig. So import only the one you would use when needed.

Or are you switching between both version depending upon the script
arguments?

jue
 
A

Andre Majorel

I think your purpose can be served by simply
doing the "uses" you want, in the order you prefer.
and turning the warnings off during this, via
use/no warnings.

Tried about twenty variations around

use POSIX;
no warnings 'redefine';
use Math::Trig;

and still get the warnings. Would you have a working example ?
 
A

Andre Majorel

No - I just googled it.

Have you tried the full "blunderbuss" of
no warnings;
just to confirm the principle?

#!/usr/bin/perl -w
no warnings;
use POSIX;
use Math::Trig;

still spits warnings. You have to remove the -w to get rid of
them. I've tried blocks, eval string, eval block, "no warnings"
inside eval. Nothing makes a difference.
 
A

Andre Majorel

Yep. That's why "use warnings" is commonly preferred nowadays, because
"-w" is global in scope and can't be disabled with "no warnings". :)

Is this is a recent development ? As I recall, "no warnings 'exec'"
used to work with -w.
 
U

Uri Guttman

AM> Thanks folks. My script evals its arguments so which subs are
AM> needed is not known at write time.

AM> I was hoping there was a way of saying "use X and quietly
AM> redefine whatever you want", or "use X but don't redefine
AM> anything". Or, at worst, "use X and import everything except
AM> this and that".

that contradicts yourself. use is a compile time operation and not
runtime and so is importing. you can't expect to have the functions you
want imported at run time like that. there are other ways to do it. try
a dispatch table with all the possible functions you support (you can't
support ALL of posix and/or trig!). then you can import them all and do
a runtime dispatch to get the function called.

uri
 
C

C.DeRykus

...
Thanks folks. My script evals its arguments so which subs are
needed is not known at write time.

I was hoping there was a way of saying "use X and quietly
redefine whatever you want", or "use X but don't redefine
anything". Or, at worst, "use X and import everything except
this and that".

IIUC, 'require' with a manual 'import' should
do what you want. (Still warns if you import
the same method from POSIX and Math of course).

require POSIX;
require Math::Trig;
...

$sub='atan'; Math::Trig->import($sub);
$sub->(...);

$sub='sin'; POSIX->import($sub);
$sub->(...);
 
I

Ilya Zakharevich

Yep. That's why "use warnings" is commonly preferred nowadays, because
"-w" is global in scope and can't be disabled with "no warnings". :)

Not "commonly". (We have been on this often.)

And in this particular case, `use warnings' looks completely useless:
I do not see any warning from

perl -le "use warnings; use POSIX; use Math::Trig; 1"

Hope this helps,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top