#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    0

    Ctime prototype mismatch error


    Hi all,

    I'm getting this weird error while maintaining some perl scripts.

    -------
    Prototype mismatch: sub XXXX::ctime (;$) vs none
    at C:/Perl/lib/Exporter.pm line 66.
    ---------

    The script is behaving fine, but these errors keep comign up.
    A Google search didn't reveal much, except people saying to ignore it. Any idea on how to get rid of them.

    I know it involves these includes:
    ----
    use Time::Local;
    use Time::localtime;
    ---

    Typically, the code uses the time as follows:
    -----------
    Code:
    my $now_tm = localtime();
    my $timestamp = sprintf( "%04d-%02d-%02dT%02d:%02d:%02d", 
    eval($now_tm->year()+1900), 
    eval($now_tm->mon()+1), 
    $now_tm->mday(), 
    $now_tm->hour(), 
    $now_tm->min(), 
    $now_tm->sec() 
    );
    -----------

    Thanks for any help on this.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Why are you using eval?

    Use the POSIX module instead of Time::Local and Time::localtime.

    Code:
    use POSIX 'strftime';
    
    my $timestamp = strftime("%Y-%m-%dT%H:%M:%S", localtime);

    Comments on this post

    • keath agrees : yes, the eval is odd
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    0
    I'm not the author of this script :P It just landed on my lap.

    Thanks for the reply though. I'll end up working with perl a bit more, so at least I know to use POSIX instead of the Time::...

    I try to minimize changing code I'm not too familiar with... especially working code. I might have to go in there and just change them all if that is the right way to do it.

    However, does anyone see a way of keeping all the evals... and just fixing up the 'use XXX' to get these warning to go away. I'd even be okay with telling perl to ignore this specific error... not sure if that is possible at all.
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,254
    Rep Power
    1810
    That code does not call the ctime() function, so it isn't the source of the error. Do you have an example that causes the warning?

    Date::Format is a module I like for a simple formatting job like the script you posted.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    0
    Originally Posted by keath
    That code does not call the ctime() function, so it isn't the source of the error. Do you have an example that causes the warning?

    Date::Format is a module I like for a simple formatting job like the script you posted.
    The error occurs on the line at the top of the file
    Code:
    use Time::localtime;
  10. #6
  11. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,254
    Rep Power
    1810
    It didn't for me. I tried your code and failed to see the error, so I am not able to help resolve the problem.

    I'm using perl 5.10
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    0
    Originally Posted by keath
    It didn't for me. I tried your code and failed to see the error, so I am not able to help resolve the problem.

    I'm using perl 5.10
    thanks keith. yeha, I am having trouble recreating the issue in a smaller file as well :P I'll post back when i get the issue resolved to a smaller file.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    0
    Originally Posted by scamper_22
    thanks keith. yeha, I am having trouble recreating the issue in a smaller file as well :P I'll post back when i get the issue resolved to a smaller file.

    aha, I think I found it. There are parts of the code that include both Time and POSIX as it goes down the use modules.


    Code:
    use strict;
    
    use Time::Local;
    use Time::localtime;
    use POSIX;
    
      my $now_tm = localtime();
      my $timestamp = sprintf( "%04d-%02d-%02dT%02d:%02d:%02d", 
    			   eval($now_tm->year()+1900), eval($now_tm->mon()+1), $now_tm->mday(), $now_tm->hour(), $now_tm->min(), $now_tm->sec() );
    
    
    print "hello ".$timestamp;
  16. #9
  17. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,254
    Rep Power
    1810
    You have a namespace collision. both Time::localtime and POSIX are exporting the function 'ctime' by default.

    You need to choose one or the other, or stop exporting them and call them both by their fully qualified names. Ex:
    Code:
    print POSIX::ctime(time);
    To turn off exporting, you can do either
    Code:
    use Time::Local;
    use Time::localtime;
    use POSIX qw//;   # stop POSIX from exporting any functions.  You will have to call them by full name
    or
    Code:
    use Time::Local;
    use Time::localtime qw/localtime/;  #stop exporting ctime, and just use localtime as a local function
    use POSIX;
    Or not export anything anywhere which avoids any collisions.

    ...or, rewrite the code to use one consistent set of functions for time.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    6
    Rep Power
    0
    yeop. I took out the POSIX use and it still runs.
    No errors.

    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo