Journal(2005) | Blog(2006) | RandomLink | WhoAmI | LiveBookmark | HomePage

<<Previous: Thank God, ubuntu rocks  >>Next: fail to embed parrot in pugs(Resolved)

随机链接

Category: Script   Keywords: random link

一个简单的脚本,功能就是获得随机的一篇 journal. :)
仅供参考

#!/usr/bin/perl

use CGI qw/redirct/; # 获取 redirect 方法用于输出 302 转网页

my $dir = "$ENV{'DOCUMENT_ROOT'}/journal"; # 网页所在的绝对路径
unless (-e $dir) { die "no such dir, please set the \$dir\n$dir non-exist"; } # 检测该路径是否存在

opendir(DIR, $dir);
my @files = readdir(DIR); # 获取所有文件
closedir(DIR);

my @wantfiles;
foreach (@files) {
    next unless (/\.html$/); # 我们只需要 HTML 文件
    next if (/^index/); # 忽略所有 index 开头的索引文件
    push(@wantfiles, $_);
}

my $total = scalar @wantfiles; # 文件的个数
my $random = int(rand($total)); # 由此获得的随机数字

print CGI::redirect("http://www.fayland.org/journal/$wantfiles[$random]"); # 转网页地址
It's a easy hack, and have fun!

<<Previous: Thank God, ubuntu rocks  >>Next: fail to embed parrot in pugs(Resolved)

Options: +Del.icio.us

Related items Created on 2005-06-04 01:00:57, Last modified on 2005-06-04 01:01:59
Copyright 2004-2005 All Rights Reserved. Powered by Eplanet && Catalyst 5.62.