Skip to Content
Perl语言入门(第8版)
book

Perl语言入门(第8版)

by Randal L. Schwartz, brian d foy, Tom Phoenix
October 2022
Beginner to intermediate
390 pages
7h 5m
Chinese
Southeast University Press
Content preview from Perl语言入门(第8版)
220
11
$dbh->disconnect();
当然,还有许多其他
DBI
能做的事,具体请参阅它的文档。虽然有些内容可能已经过
时,不过
Programming the Perl DBI
一书仍然是该模块的优秀指南。
处理日期和时间的模块
能够处理日期和时间的模块有许许多多,不过眼下最受欢迎的是
Christian Hansen
写的
Time::Moment
模块。它提供了几乎完整的用于处理日期和时间的功能。你可以
CPAN
获取该模块。
如果
Time::Moment
不能满足需要,可以选用
DateTime
模块,它也提供了完备
的解决方案。不过这个模块复杂老道,对一般的使用来说略重,但这算是完备
的代价吧。
最常见的需求是把系统中以秒数表示的当前时间(或者纪元时间)转换成一
Time::Moment
对象:
use Time::Moment;
my $dt = Time::Moment->from_epoch( time );
或者省略参数,直接用
now
方法取得当前时间:
my $dt = Time::Moment->now;
此后,我们可以取得日期各个部分的数据:
printf '%4d%02d%02d', $dt->year, $dt->month, $dt->day_of_month;
如果有两个
Time::Moment
对象,还可以用它们进行日期计算:
my $dt1 = Time::Moment->new(
year => 1987,
month
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787576602036