我在下面编写了以下相对简单的代码,抛出一个弹出框提醒我日常任务。
#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);
现在,代码可以运行,但会发出警告。另外两个my $days
也可以正常工作而不会发出警告。这是POSIX功能显示的警告。
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.
我认为我以前没有将POSIX
与Win32
结合使用,我可以看到他们都在调用类似命名的函数NULL
。但我不知道该怎么办。
我喜欢使用这两个模块,但显然,我不希望在更复杂的项目中出现这种情况。
发出警告的是什么,我怎么能简单地避开它?
答案 0 :(得分:4)
你是正确的,默认情况下,POSIX和Win32导出NULL
。
POSIX是一个表现不佳的模块,默认情况下输出远,远,太多(在底部列表)。为此,只导入您需要的功能。
use Win32;
use POSIX qw(floor);
POSIX使用Exporter来完成此任务。有关控制导入内容的更多详细信息,请参阅How To Import。
$ perl -wle'使用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,删除,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,ECH ILD,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 E重新启动,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 ,时钟,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,获取,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_N AME_MAX,ECANCELED,SIGCHLD,EREMOTE,FLT_MAX_EXP,SEEK_SET,getpid,B1800,NOFLSH,SIGUSR1,ECONNRESET,wcstombs,ESPIPE,WSTOPSIG,倒带,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,断言,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,实验室,CLOCAL,R_OK,memcpy,F_GETFL,VTIME,dup,EALREA DY,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,免费, fputc,NGROUPS_MAX,FLT_DIG