<?xml version="1.0" encoding="gbk"?>
<rss version="2.0">
  <channel>
    <title>曲径通幽论坛 - Functions</title>
    <link>http://www.groad.net/bbs/forum.php?mod=forumdisplay&amp;fid=122</link>
    <description>Latest 20 threads of Functions</description>
    <copyright>Copyright(C) 曲径通幽论坛</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Sun, 03 May 2026 01:16:44 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://www.groad.net/bbs/static/image/common/logo_88_31.gif</url>
      <title>曲径通幽论坛</title>
      <link>http://www.groad.net/bbs/</link>
    </image>
    <item>
      <title>chop()/chomp() -- 去掉变量最后一个字符</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7294</link>
      <description><![CDATA[chop() 和 chomp() 用来删除变量的最后一个字符，或者是数组中每个元素的最后一个字符，并返回修改后的值。

chop() 一般用来删除程序接收到的输入行末尾的换行符，这些输入行可以来自 STDIN，文件或者命令置换结果。

chomp() 是 Perl5 中引入的函数，它和 chop() 的作 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Mon, 16 Jul 2012 16:15:18 +0000</pubDate>
    </item>
    <item>
      <title>ref -- 判断引用是否存在并返回引用指向的数据类型</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=5074</link>
      <description><![CDATA[ref 函数可以用来判断引用是否存在。如果它的参数是一个指针(引用)变量，那么 ref 就返回该引用指向的数据类型。比如指针指向的是标量，那么返回 SCALAR；又如指向的是数组，那么返回 ARRAY 。

如果其参数不是引用，那么返回一个 NULL 字符串，下面是 ref 函数的可能返 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 25 Oct 2011 12:50:46 +0000</pubDate>
    </item>
    <item>
      <title>eval -- 计算表达式值, $@ 变量记录 eval 错误信息</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=5041</link>
      <description><![CDATA[eval 函数用来计算表达式的值，它常用于捕捉错误和处理异常。位于 eval 之后的语句块是作为单独的 Perl 程序来处理和解析的，其中的所有变量设置，子例程以及格式定义都将保持到 eval 执行完毕。

eval 的返回值是上一个表达式的值，如果出现编译错误，运行时错误，或者 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Fri, 21 Oct 2011 03:49:37 +0000</pubDate>
    </item>
    <item>
      <title>sprintf -- 格式化数据</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4987</link>
      <description><![CDATA[sprintf 常见的用法是用来格式化浮点数，它使小数点后具有特定精度的数值，比如：
[code=perl]my $val = sprintf \&quot;%.2f\&quot;, 2.338238;
print \&quot;$val\\n\&quot;;[/mw_shl_code]
输出：2.34
 
 
一个实例：
 [code=perl]#!/usr/bin/perl

sub big_money {

&#160;&#160;&#160;&#160; ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Thu, 13 Oct 2011 03:22:47 +0000</pubDate>
    </item>
    <item>
      <title>substr -- 处理字串</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4984</link>
      <description><![CDATA[substr 函数可以用来处理字串，使用方法如下：

 
第 1 个参数表示要处理的字符串，第 2 个参数表示从第 1 个参数所表示的字符串的那个位置开始查找，第 3 个参数表示字串的长度。
 
 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 11:07:29 +0000</pubDate>
    </item>
    <item>
      <title>index --- 查找字串首次出现位置 | rindex --- 查找字串最后一次出现位置</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4983</link>
      <description><![CDATA[index 函数用来查找一个字符串种的字串，并返回这个字串所处的位置(从 0 开始算起)。一般使用如下代码所示：
[mw_shl_code=perl,true]#!/usr/bin/perl

$big = \&quot;hello world\&quot;;
$small = \&quot;wor\&quot;;

$where = index($big, $small);

print \&quot;we got at $where\\n\&quot;;[/mw_shl_co ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 07:22:55 +0000</pubDate>
    </item>
    <item>
      <title>utime -- 更改时间戳</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4982</link>
      <description><![CDATA[有时候可能需要修改一下文件的时间。关于文件的时间戳一共有 3 个：
 
modification time (mtime,修改时间) ：该时间在修改文件后被设置。
 
access time (atime,访问时间) ：当文件被读取时，该时间被修改。
 
status time (ctime,状态时间) ：该时间为“状态时间”， ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 06:49:20 +0000</pubDate>
    </item>
    <item>
      <title>chown -- 更改文件隶属 | getpwnam -- 转换用户 | getgrnam -- 转换组</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4981</link>
      <description><![CDATA[chown 函数用来更改文件的拥有者和所属组，使用 chown 时拥有者和组参数是以数字形式出现的，如：

运行下面程序：

处理结果：

记住数 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 05:54:38 +0000</pubDate>
    </item>
    <item>
      <title>mkdir -- 创建目录 | rmdir -- 删除空目录 | 删除非空目录方法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4979</link>
      <description><![CDATA[mkdir 用来创建目录。

考虑下面代码：
[mw_shl_code=perl,true]#!/usr/bin/perl

mkdir \&quot;temp\&quot;, 0755 or warn \&quot;Cannot make temp directory: $!\&quot;;

my $name = \&quot;hello\&quot;;
my $permissions = \&quot;07555\&quot;;
mkdir $name, oct($permissions);

#从命令行指定目录名字和权限
my  ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 04:07:24 +0000</pubDate>
    </item>
    <item>
      <title>symlink -- 建立软连接 | readlink -- 读取链接</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4977</link>
      <description><![CDATA[symlink 用来建立软链接，而 readlink 用来读取链接信息，它返回的是软连接所指向的目标文件的绝对路径。

测试代码：
[mw_shl_code=perl,true]#!/usr/bin/perl

symlink \&quot;/usr/src/linux-source-2.6.39.4/\&quot;,\&quot;/root/myperl/chap13/linux\&quot; or warn \&quot;cannot symlink linux ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 02:46:13 +0000</pubDate>
    </item>
    <item>
      <title>link -- 建立硬连接</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4976</link>
      <description><![CDATA[link 函数用来建立一个文件的硬连接。使用很简单：

硬连接的特点是硬连接文件的 inode 和原文件是同一个，删除掉原文件或者硬连接文件都不会使数据被删除，只是 inode 链接数减少一个而已。当然，两个文件都删除的话，数据就会丢失。
 
注意，不能为目录建立硬连接。如 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Wed, 12 Oct 2011 02:14:26 +0000</pubDate>
    </item>
    <item>
      <title>File::Copy move --- 移动文件</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4974</link>
      <description><![CDATA[使用 File::Copy 模块中的 move 函数可以像命令 mv 那样移动一个文件到一个目录中，考虑下面代码：



上面程序中，将当前目录下的 t ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 15:46:41 +0000</pubDate>
    </item>
    <item>
      <title>rename -- 重命名文件</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4971</link>
      <description><![CDATA[rename 函数用来重命名文件。它的一般使用方法很简单：

可以利用正则表达式进行批量改名，比如将当前目录下所有后缀名为 .txt 的文件全部修改为 .bak 后缀的：


运行下面程序：
[mw_shl_code=perl,true]#!/usr/bin/perl

foreach my $file (glob \&quot;*.txt\&quot;) {
        m ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 13:32:58 +0000</pubDate>
    </item>
    <item>
      <title>chmod -- 改变文件权限</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4969</link>
      <description><![CDATA[和 Unix/Linux 下的 chmod 命令一样，Perl 也有 chmod  函数，用来改变文件的权限，用法很简单：


运行后查看相关文件信息：

需要注意的是，该函数的第 2 个参数，即权 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 11:40:47 +0000</pubDate>
    </item>
    <item>
      <title>opendir, readdir, closedir 操作目录句柄</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4968</link>
      <description><![CDATA[操作目录，或者说操作目录句柄时，常用到 3 个函数：opendir , readdir 以及 closedir 。

opendir 打开目录，readdir 读取目录中的内容(文件名)，closedir 关闭目录。

测试代码：
[mw_shl_code=perl,true]#!/usr/bin/perl

my $dir = \&quot;/etc\&quot;;

opendir DH, $dir or di ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 09:08:51 +0000</pubDate>
    </item>
    <item>
      <title>unlink -- 删除文件</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4967</link>
      <description><![CDATA[使用 unlink 删除文件，比如： unlink \&quot;hello.txt\&quot;, \&quot;world.txt\&quot;;

结合 glob 操作符可以删除多个相同类型的文件：
unlink glob \&quot;*.txt\&quot;;

unlink 的返回值是成功删除掉的文件数，如：




运行下面程序：
[mw_shl_code=perl,true]#!/usr/bin/perl

my $count = unlink  ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 05:08:26 +0000</pubDate>
    </item>
    <item>
      <title>time | gmtime | localtime</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4965</link>
      <description><![CDATA[time 函数返回 UNIX 时间，格式如：1318301827 。

gmtime 函数返回的是世界标准时间(UTC，加上时间差后记得本地时间 localtime )，函数的返回值是一个字符串，如：Tue Oct 11 02:57:07 2011 。

localtime 返回本地时间，如果不加参数的话，返回的也是个字符串：Tue Oc ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 03:29:06 +0000</pubDate>
    </item>
    <item>
      <title>stat 与 lstat 函数</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4964</link>
      <description><![CDATA[stat 或 lstat 函数可以返回文件的许多属性信息，比如文件连接数，文件拥有者的UID 及 组的 GID 等。它可以带有文件句柄(包括 )，或是某个会返回文件名的表达式。如果函数执行失败(通常是因为无效的文件名或是文件不存在)，它会返回一个空列表，否则返回一个含有 13 个 ...]]></description>
      <category>Functions</category>
      <author>beyes</author>
      <pubDate>Tue, 11 Oct 2011 02:30:01 +0000</pubDate>
    </item>
  </channel>
</rss>