POSIX and Math::Trig

Discussion in 'Perl Misc' started by Andre Majorel, Sep 6, 2010.

  1. 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.

    --
    André Majorel http://www.teaser.fr/~amajorel/
    "This album is very well mixed, so it is difficult to tell
    what is what."
     
    Andre Majorel, Sep 6, 2010
    #1
    1. Advertising

  2. Andre Majorel <> writes:

    > 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
     
    Peter Makholm, Sep 6, 2010
    #2
    1. Advertising

  3. On 2010-09-06, Ben Morrow <> wrote:
    >
    > Quoth 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

    >
    > 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".

    --
    André Majorel http://www.teaser.fr/~amajorel/
    "This album is very well mixed, so it is difficult to tell
    what is what."
     
    Andre Majorel, Sep 6, 2010
    #3
  4. Andre Majorel <> wrote:
    >On 2010-09-06, Ben Morrow <> wrote:
    >>
    >> Quoth 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

    >>
    >> 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.


    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
     
    Jürgen Exner, Sep 6, 2010
    #4
  5. On 2010-09-06, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
    > Andre Majorel wrote:
    >
    >> 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".

    >
    > 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 ?

    --
    André Majorel http://www.teaser.fr/~amajorel/
    "This album is very well mixed, so it is difficult to tell
    what is what."
     
    Andre Majorel, Sep 6, 2010
    #5
  6. On 2010-09-06, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
    > Andre Majorel wrote:
    >> On 2010-09-06, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
    >>> Andre Majorel wrote:
    >>>
    >>>> 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".
    >>> 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 ?

    >
    > 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.

    --
    André Majorel http://www.teaser.fr/~amajorel/
    "This album is very well mixed, so it is difficult to tell
    what is what."
     
    Andre Majorel, Sep 6, 2010
    #6
  7. On 2010-09-06, Sherm Pendley <> wrote:
    > Andre Majorel <> writes:
    >
    >> #!/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.

    >
    > 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.

    --
    André Majorel http://www.teaser.fr/~amajorel/
    "This album is very well mixed, so it is difficult to tell
    what is what."
     
    Andre Majorel, Sep 6, 2010
    #7
  8. Andre Majorel

    Uri Guttman Guest

    >>>>> "AM" == Andre Majorel <> writes:

    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

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Sep 6, 2010
    #8
  9. Andre Majorel

    C.DeRykus Guest

    On Sep 6, 4:52 am, Andre Majorel <> wrote:
    > ...
    > 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->(...);

    --
    Charles DeRykus
     
    C.DeRykus, Sep 6, 2010
    #9
  10. On 2010-09-06, Sherm Pendley <> wrote:
    > 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
     
    Ilya Zakharevich, Sep 6, 2010
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Healey
    Replies:
    7
    Views:
    1,540
    Tim Prince
    May 22, 2006
  2. kwikius
    Replies:
    1
    Views:
    399
    Default User
    May 22, 2008
  3. kwikius
    Replies:
    1
    Views:
    359
    Default User
    May 22, 2008
  4. John
    Replies:
    2
    Views:
    114
  5. VK
    Replies:
    15
    Views:
    1,279
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page