【发布时间】:2011-04-11 23:35:44
【问题描述】:
你好,
我有以下代码,我一直在想如何继续修改它,所以它会询问目录,读取目录中的所有文件,然后提取特定字符串并输出到 html 文件?提前致谢。
#!/usr/local/bin/perl
use warnings;
use strict;
use Cwd;
print "Enter filename: "; # Should be Enter directory
my $perlfile =STDIN;
open INPUT_FILE, $perlfile || die "Could not open file: $!";
open OUTPUT, '>out.html' || die "Could not open file: $!";
# Evaluates the file and imports it into an array.
my @comment_array = ;
close(INPUT_FILE);
chomp @comment_array;
@comment_array = grep /^\s*#/g, @comment_array;
my $comment;
foreach $comment (@comment_array) {
$comment =~ /####/; #Pattern match to grab only #s
# Prints comments to screen
Print results in html format
# Writes comments to output.html
Writes results to html file
}
close (OUTPUT);
【问题讨论】:
标签: perl pattern-matching