Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I wrote the following relatively simple code below, to throw a popup box to remind me of daily tasks.

#use Math::Round;
use POSIX;
use Win32;

use strict;
use warnings;

my $basetime = 1484784000;

#code with POSIX
my $days = floor((time()-$basetime) / 86400);

#code without POSIX
#my $days = sprintf("%d", (time()-$basetime) / 86400);

#code with Math::Round
#my $days = Math::Round::nearest_floor(1, (time()-$basetime) / 86400);

my $bigString = "We've been going for $days days.\n";

Win32::MsgBox($bigString);

Now, the code works but throws a warning. The other two my $days work as well without throwing a warning. Here is the warning the POSIX function shows.

Constant subroutine main::NULL redefined at C:/Strawberry/perl/lib/Exporter.pm line 66.
 at C:\coding\perl\posix-win32.pl line 3.
Prototype mismatch: sub main::NULL () vs none at C:/Strawberry/perl/lib/Exporter.pm line 66.
 at C:\coding\perl\posix-win32.pl line 3.

I don't think I ever used POSIX in conjunction with Win32, before, and I can see they're both calling a similarly named function, NULL. But I don't know what to do about it.

I like using both modules, but obviously, I wouldn't want this cropping up in more complicated projects.

What is going on to throw the warning, and how could I avoid it simply?

share|improve this question
5  
Post your EXACT warning message. – toolic Jan 19 at 17:04
3  
Only import the functions you need: use POSIX qw(floor); – toolic Jan 19 at 17:05
1  
What did you see to make you believe that both modules call a thing named NULL? – Borodin Jan 19 at 17:09
1  
If $days will never be negative, int will give the same value as floor. Just food for thought. – Mr. Llama Jan 19 at 17:13
    
@toolic thanks. That solves the problem nicely. Also, fixed not printing the warning message. I thought I checked for it, but I didn't. Mr.Llama, that's a good idea. I just started using floor years ago but never changed it. I suppose the question was more about clashing modules, but I'm glad to be able to incorporate other tweaks into my code. – aschultz Jan 19 at 17:26
up vote 4 down vote accepted

You're correct, both POSIX and Win32 export, by default, NULL.

POSIX is a poorly behaved module that exports far, far, far too much by default (list at the bottom). To account for this, only import the functions you need.

use Win32;
use POSIX qw(floor);

POSIX uses Exporter to accomplish this. See How To Import for more detail about controlling what gets imported.

$ perl -wle 'use POSIX; print join ", ", @POSIX::EXPORT'

isupper, isspace, fabs, F_GETLK, strncpy, EBADMSG, localeconv, SIGTRAP, ctermid, S_ISUID, fwrite, pow, strcoll, S_ISBLK, _POSIX_STREAM_MAX, EACCES, putc, FILENAME_MAX, tolower, sinh, EMLINK, ESOCKTNOSUPPORT, EDESTADDRREQ, DBL_MIN, fopen, TOSTOP, strncat, LINK_MAX, ENXIO, INLCR, TCION, NAME_MAX, EINPROGRESS, SIGILL, NDEBUG, VEOF, SEEK_END, ungetc, SEEK_CUR, STDOUT_FILENO, VEOL, ftell, UINT_MAX, ENOTEMPTY, DBL_EPSILON, INPCK, WIFSIGNALED, B134, remove, LC_TIME, SIGSEGV, _POSIX_PATH_MAX, F_RDLCK, SIG_BLOCK, VINTR, SA_NOCLDSTOP, PATH_MAX, isdigit, log10, O_RDWR, ENOTCONN, TMP_MAX, signal, F_SETLKW, qsort, O_TRUNC, _SC_TZNAME_MAX, _POSIX_NGROUPS_MAX, LC_COLLATE, _PC_NO_TRUNC, SCHAR_MAX, EHOSTUNREACH, fputs, ctime, fgetc, O_APPEND, _POSIX_ARG_MAX, EWOULDBLOCK, TCSAFLUSH, strstr, _exit, execle, malloc, DBL_MANT_DIG, _POSIX_SSIZE_MAX, puts, _SC_JOB_CONTROL, ttyname, B150, EMFILE, CS6, _POSIX_LINK_MAX, asin, mblen, _POSIX_PIPE_BUF, sigsuspend, B600, SIGPROF, L_ctermid, _SC_CLK_TCK, ceil, ECHILD, tmpfile, isprint, ECHOE, memset, ENOLINK, atexit, MAX_CANON, EADDRINUSE, sigprocmask, stderr, fscanf, modf, setpgid, tcgetpgrp, toupper, ENETRESET, B2400, raise, S_ISDIR, _SC_PAGESIZE, DBL_MAX_EXP, sysconf, EIDRM, F_SETFD, O_NOCTTY, EHOSTDOWN, FLT_MAX, CSTOPB, S_IRWXU, EPROTO, TCSANOW, S_IRWXO, setbuf, strchr, strerror, FLT_MIN_EXP, TCIOFF, tan, SIGCONT, EDQUOT, MB_CUR_MAX, _PC_PATH_MAX, SIGTTOU, SIGXCPU, EROFS, fdopen, _PC_VDISABLE, CHILD_MAX, ETXTBSY, S_ISCHR, SIGTTIN, VERASE, ESRCH, LONG_MAX, mbtowc, pause, sscanf, MB_LEN_MAX, O_WRONLY, fstat, _PC_MAX_INPUT, F_SETLK, SIGHUP, S_IXUSR, ETIME, DBL_MAX_10_EXP, execvp, ENOTSOCK, DBL_MIN_10_EXP, TCSADRAIN, isalnum, getchar, EMSGSIZE, TCIOFLUSH, _SC_NGROUPS_MAX, FLT_RADIX, ENOTDIR, _PC_LINK_MAX, strspn, S_IRWXG, _POSIX_NO_TRUNC, EXIT_SUCCESS, VKILL, acos, ERESTART, vprintf, EPFNOSUPPORT, IGNCR, _PC_MAX_CANON, STDIN_FILENO, strxfrm, _SC_VERSION, isxdigit, setsid, _POSIX_NAME_MAX, fmod, VSTART, B9600, FLT_MANT_DIG, islower, EXIT_FAILURE, clock, ENETDOWN, CS7, strrchr, SIGUSR2, tcdrain, INT_MIN, LDBL_DIG, _POSIX_JOB_CONTROL, SIG_UNBLOCK, _SC_STREAM_MAX, X_OK, F_UNLCK, ETIMEDOUT, CHAR_BIT, tmpnam, W_OK, sigpending, cfgetospeed, IEXTEN, geteuid, SIGRTMAX, E2BIG, LDBL_MIN, _SC_CHILD_MAX, CLK_TCK, NCCS, tzset, ENOMEM, gets, BRKINT, EDOM, ENODATA, ENOBUFS, ISTRIP, CLOCKS_PER_SEC, LDBL_MIN_EXP, SHRT_MIN, PARODD, EOF, asctime, ENFILE, EPROCLIM, freopen, sigaction, F_DUPFD, O_ACCMODE, FLT_MAX_10_EXP, difftime, TCOFLUSH, EINTR, ENOMSG, L_cuserid, B4800, EAGAIN, TCOON, setjmp, TZNAME_MAX, S_IWOTH, cuserid, PIPE_BUF, strtol, HUGE_VAL, F_GETFD, IGNPAR, EBUSY, memmove, ENOTBLK, getgid, SIGINT, EUSERS, SIGURG, EDEADLK, EOWNERDEAD, creat, _POSIX_MAX_CANON, _POSIX_CHOWN_RESTRICTED, execlp, F_SETFL, stdout, SIG_DFL, ldiv, SIGKILL, VSUSP, ENOTRECOVERABLE, B300, B200, HUPCL, WTERMSIG, offsetof, clearerr, tanh, getcwd, LDBL_MAX_10_EXP, SIG_SETMASK, ECHONL, O_NONBLOCK, S_IXOTH, ECONNABORTED, F_OK, tcflush, _POSIX_SAVED_IDS, SIGPIPE, _PC_NAME_MAX, ECANCELED, SIGCHLD, EREMOTE, FLT_MAX_EXP, SEEK_SET, getpid, B1800, NOFLSH, SIGUSR1, ECONNRESET, wcstombs, ESPIPE, WSTOPSIG, rewind, BUFSIZ, SIGABRT, STREAM_MAX, vsprintf, tcsendbreak, LDBL_MIN_10_EXP, pathconf, S_IRGRP, _SC_SAVED_IDS, OPOST, execv, feof, O_EXCL, access, sigsetjmp, mktime, fread, B1200, LC_MESSAGES, EXDEV, S_IROTH, longjmp, SA_RESETHAND, LC_ALL, ENOSYS, calloc, B110, FLT_EPSILON, assert, VQUIT, B50, ICANON, IXON, ECONNREFUSED, strftime, _PC_PIPE_BUF, ERANGE, SA_ONSTACK, ispunct, _POSIX_MAX_INPUT, WIFSTOPPED, ldexp, ENOLCK, EOTHER, _PC_CHOWN_RESTRICTED, PARENB, O_CREAT, STDERR_FILENO, ARG_MAX, ETOOMANYREFS, isatty, S_ISFIFO, SIGQUIT, abort, EPIPE, isalpha, USHRT_MAX, SA_RESTART, bsearch, IGNBRK, stdin, EPROTONOSUPPORT, ENOSPC, fgets, getegid, EAFNOSUPPORT, setvbuf, SIGTSTP, getuid, ESHUTDOWN, LONG_MIN, fgetpos, _POSIX_VERSION, frexp, %SIGRT, EADDRNOTAVAIL, F_WRLCK, lseek, EISDIR, atol, cfsetospeed, SIGALRM, fpathconf, B38400, L_tmpname, _POSIX_OPEN_MAX, ESTALE, LC_CTYPE, S_ISREG, WIFEXITED, EPROTOTYPE, SIG_IGN, EIO, ENAMETOOLONG, EPERM, atoi, isgraph, ENOENT, errno, MAX_INPUT, setuid, _SC_OPEN_MAX, S_IRUSR, siglongjmp, getenv, CS8, EINVAL, NULL, ECHO, LDBL_EPSILON, SCHAR_MIN, ENETUNREACH, uname, DBL_MAX, ENOPROTOOPT, SIGSTOP, strtoul, SA_NODEFER, CREAD, SIGBUS, mbstowcs, EFBIG, cfsetispeed, ISIG, FLT_MIN, SA_NOCLDWAIT, fsync, LDBL_MAX_EXP, ENOTTY, VMIN, strtod, TCIFLUSH, SA_SIGINFO, fclose, strcspn, strpbrk, SIGTERM, ENOSTR, ULONG_MAX, LC_NUMERIC, scanf, getgroups, vfprintf, ENOSR, FLT_ROUNDS, EEXIST, S_IWGRP, ENOEXEC, SIGVTALRM, SIGPOLL, memcmp, atan, putchar, _POSIX_CHILD_MAX, fflush, fsetpos, WEXITSTATUS, atof, EFAULT, memchr, strcat, VSTOP, _POSIX_TZNAME_MAX, LDBL_MAX, strlen, setlocale, FLT_MIN_10_EXP, cosh, tcgetattr, realloc, div, CHAR_MAX, fprintf, UCHAR_MAX, execve, B75, ICRNL, strcpy, ECHOK, FD_CLOEXEC, cfgetispeed, iscntrl, strtok, SSIZE_MAX, SIGSYS, S_ISGID, strncmp, EISCONN, labs, CLOCAL, R_OK, memcpy, F_GETFL, VTIME, dup, EALREADY, fseek, strcmp, SIGXFSZ, dup2, wctomb, SHRT_MAX, SIGFPE, SIG_ERR, _SC_ARG_MAX, setgid, execl, RAND_MAX, CSIZE, tcflow, CS5, LC_MONETARY, TCOOFF, _POSIX_VDISABLE, PARMRK, perror, mkfifo, ENODEV, S_IXGRP, WNOHANG, ferror, WUNTRACED, floor, INT_MAX, EOPNOTSUPP, OPEN_MAX, LDBL_MANT_DIG, DBL_DIG, SIGRTMIN, CHAR_MIN, tzname, O_RDONLY, B0, tcsetattr, tcsetpgrp, ELOOP, EOVERFLOW, S_IWUSR, IXOFF, EILSEQ, DBL_MIN_EXP, ENOTSUP, EBADF, B19200, free, fputc, NGROUPS_MAX, FLT_DIG

share|improve this answer
4  
Not importing from Win32 (use Win32 qw( );) would be good too. It only exports a few rarely-used constants (no functions!). – ikegami Jan 19 at 19:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.