13.07.2015 Views

Perl 语言编程 - Linux教程

Perl 语言编程 - Linux教程

Perl 语言编程 - Linux教程

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

数 据 域内 容USERHOME这 个 对 象 代 表 谁 的 点 文 件那 些 点 文 件 在 哪 里CLOBBER 我 们 是 否 允 许 修 改 或 者 删 除 这 些 点 文 件CONTENTS 点 文 件 名 字 和 内 容 映 射 的 散 列下 面 是 DotFiles ? .pm 的 开 头 :package DotFiles;use Carp;sub whowasi { (caller(1))[3]. "()" }my $DEBUG = 0;sub debug { $DEBUGA = @_ ? shift: 1}对 于 我 们 的 例 子 而 言 , 我 们 希 望 打 开 调 试 输 出 以 便 于 在 开 发 中 的 跟 踪 , 因 此 我 们 为 此 设 置 了$DEBUG。 我 们 还 写 了 一 个 便 利 函 数 放 在 内 部 以 便 于 打 印 警 告 :whowasi 返 回 调 用 了 当 前函 数 的 那 个 函 数 的 名 字 (whowasi 是 “ 祖 父 辈 ” 的 函 数 )。下 面 就 是 DotFiles ?捆 绑 散 列 的 方 法 :CLASSNAME->TIEHASH(LIST)这 里 是 DotFiles ?构 造 器 :sub TIEHASH {my $self = shift;my $user = shift || $>;my $dotdir = shift || "";croak "usage: @{[ &whowasi ] } [ USER [DOTDIR]]" if @_;$user = getpwuid($user) if $user =~ /^\d+$/;369

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!