Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Subroutine Time::HiRes::Time redefined ... Help

by sweetblood (Prior)
on May 03, 2018 at 21:19 UTC ( #1214026=perlquestion: print w/replies, xml ) Need Help??

sweetblood has asked for the wisdom of the Perl Monks concerning the following question:

I'm banging my head against a pile of "Subroutine Yada::Yada redefined ..." errors. I have pared my script to just use commands, yet they continue. Here is what I've got:
#!/usr/bin/perl -w use strict; use v5.10; use POE; use File::Copy; use MIME::Lite; use Time::Piece; use Data::Dumper; use File::Basename; use Net::SFTP::Foreign; #use Win32::Process::Info; use POE::Component::DirWatch::Object; use IPC::System::Simple qw(system); use sigtrap qw(die untrapped normal-signals error-signals);
And here is what I get:
Subroutine AUTOLOAD redefined at C:/Strawberry/perl/site/lib/Time/HiRe +s.pm line 36. Subroutine import redefined at C:/Strawberry/perl/site/lib/Time/HiRes. +pm line 54. Subroutine tv_interval redefined at C:/Strawberry/perl/site/lib/Time/H +iRes.pm line 75. Subroutine Time::HiRes::CLONE redefined at C:/Strawberry/perl/site/lib +/Time/HiRes.pm line 71. Subroutine Time::HiRes::constant redefined at C:/Strawberry/perl/site/ +lib/Time/HiRes.pm line 71. Subroutine Time::HiRes::usleep redefined at C:/Strawberry/perl/site/li +b/Time/HiRes.pm line 71. Subroutine Time::HiRes::nanosleep redefined at C:/Strawberry/perl/site +/lib/Time/HiRes.pm line 71. Subroutine Time::HiRes::sleep redefined at C:/Strawberry/perl/site/lib +/Time/HiRes.pm line 71. Subroutine Time::HiRes::ualarm redefined at C:/Strawberry/perl/site/li +b/Time/HiRes.pm line 71. Subroutine Time::HiRes::alarm redefined at C:/Strawberry/perl/site/lib +/Time/HiRes.pm line 71. Subroutine Time::HiRes::gettimeofday redefined at C:/Strawberry/perl/s +ite/lib/Time/HiRes.pm line 71. Subroutine Time::HiRes::time redefined at C:/Strawberry/perl/site/lib/ +Time/HiRes.pm line 71. Subroutine Time::HiRes::clock_gettime redefined at C:/Strawberry/perl/ +site/lib/Time/HiRes.pm line 71. Subroutine Time::HiRes::clock_getres redefined at C:/Strawberry/perl/s +ite/lib/Time/HiRes.pm line 71. Subroutine Time::HiRes::clock_nanosleep redefined at C:/Strawberry/per +l/site/lib/Time/HiRes.pm line 71. Subroutine Time::HiRes::clock redefined at C:/Strawberry/perl/site/lib +/Time/HiRes.pm line 71. Subroutine Time::HiRes::lstat redefined at C:/Strawberry/perl/site/lib +/Time/HiRes.pm line 71. Subroutine Time::HiRes::stat redefined at C:/Strawberry/perl/site/lib/ +Time/HiRes.pm line 71.

This is driving me nuts. I admit to being an on again off again perl user.
Please let me know what is going on if you can.

Thanks!

Sweetblood

Replies are listed 'Best First'.
Re: Subroutine Time::HiRes::Time redefined ... Help
by hippo (Chancellor) on May 03, 2018 at 22:07 UTC

    Which version of Time::HiRes are you using? Which version of perl? Which versions of all the other modules?

    I don't have POE::Component::DirWatch::Object installed here, but taking that out it runs cleanly for me.

    For the record, it's considered better practice to do

    #!/usr/bin/perl use warnings;

    in preference to

    #!/usr/bin/perl -w
      I thought along that same line of thinking and upgraded Time::HiRes, no help.
      But, It seems use warnings; Did it! Errors are gone. It seemed a more stylistic choice, but it fixed it. Can you explain?

      Sweetblood

        Basically, the -w flag is an all-or-nothing construct. It enables warnings everywhere in your code, including in the modules you use and you haven't written yourself. The use warnings; pragma, by contrast, is lexically scoped, so it does not overlap on other pieces of code used in your program. And you can turn it on or off for some chunks of code or for some specific warnings categories.

        I basically use the -w flag only for one-liners. The use warnings; pragma is much better for all other cases.

        See https://perldoc.perl.org/warnings.html#What's-wrong-with-*-w*-and-%24%5eW for more details.

Re: Subroutine Time::HiRes::Time redefined ... Help
by rminner (Chaplain) on May 07, 2018 at 01:59 UTC
    In perl on windows you will get a warning for every subroutine in a Module being redefined, if somewhere in your code (or in some submodule) the given Module is used or required with the correct case, and somewhere else it is loaded with a missmatched case. e.g. in one place it is loaded using the correct case:
    use Time::HiRes;
    an it is loaded somewhere else with the wrong case:
    # missspelled module name use TIME::HiRes;
    Since TIME::HiRes is not loaded yet (only Time::HiRes is loaded), it will be loaded again, thus redefining the subroutines. The cause is Perl being case sensitive and the windows filesystem being case insensitive.

      Good point. Having a look at %INC could help:

      C:\>perl -MData::Dumper -MdaTA::duMPer -E "say Dumper(\%INC)" $VAR1 = { 'daTA/duMPer.pm' => 'C:/strawberry/perl/lib/daTA/duMPer.pm', 'warnings/register.pm' => 'C:/strawberry/perl/lib/warnings/r +egister.pm', 'bytes.pm' => 'C:/strawberry/perl/lib/bytes.pm', 'XSLoader.pm' => 'C:/strawberry/perl/lib/XSLoader.pm', 'Carp.pm' => 'C:/strawberry/perl/lib/Carp.pm', 'Exporter.pm' => 'C:/strawberry/perl/lib/Exporter.pm', 'strict.pm' => 'C:/strawberry/perl/lib/strict.pm', 'warnings.pm' => 'C:/strawberry/perl/lib/warnings.pm', 'overload.pm' => 'C:/strawberry/perl/lib/overload.pm', 'Data/Dumper.pm' => 'C:/strawberry/perl/lib/Data/Dumper.pm', 'feature.pm' => 'C:/strawberry/perl/lib/feature.pm' }; C:\>

      Sorting the %INC keys definitively helps:

      C:\>perl -MData::Dumper -MdaTA::duMPer -E "say for sort { lc($a) cmp l +c($b) } keys %INC" bytes.pm Carp.pm daTA/duMPer.pm Data/Dumper.pm Exporter.pm feature.pm overload.pm strict.pm warnings.pm warnings/register.pm XSLoader.pm C:\>

      But the best way is to let perl find the problematic module name:

      C:\>perl -MData::Dumper -MdaTA::duMPer -E "my %oops; $oops{lc $_}++ fo +r keys %INC; say for grep { $oops{$_}>1 } keys %oops" data/dumper.pm C:\>

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1214026]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2020-09-23 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (131 votes). Check out past polls.

    Notices?