[英]Perl: Undefined subroutine &main::gmdate?
這是我正在嘗試做的事情(沒什么復雜的):
use Digest::MD5 qw(md5 md5_hex md5_base64);
$apikey = '1234';
$secret = '123';
$timestamp = gmdate('U');
$sig = md5($apikey . $secret . $timestamp);
echo $sig
因此,錯誤發生在 $timestamp = gmdate 行上。
我究竟做錯了什么?
我認為您正在尋找gmtime
function,而不是gmdate
function。 雖然,現在我看到您正在將'U'
傳遞給它,但我很困惑。
啊,我現在明白了, PHP 使用gmdate('U')
就像 Perl 5 使用gmtime()
一樣。
哎呀,我的 memory 失敗了,你需要使用Time::Local
或POSIX::mktime
將localtime
或gmtime
的結果轉換為紀元秒。
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/mktime/;
use Time::Local qw/timegm/;
print "the time is now ", timegm(localtime()), " or ", mktime(gmtime()), "\n";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.