我在目录中有一些文本文件,我想解析它们的内容并将其写入文件。到目前为止,我使用的代码是这样的:
#!/usr/bin/perl
#The while loop repeats the execution of a block as long as a certain condition is evaluated true
use strict; # Always!
use warnings; # Always!
my $header = 1; # Flag to tell us to print the header
while (<*.txt>) { # read a line from a file
if ($header) {
# This is the first line, print the name of the file
**print "========= $ARGV ========\n";**
# reset the flag to a false value
$header = undef;
}
# Print out what we just read in
print;
}
continue { # This happens before the next iteration of the loop
# Check if we finished the previous file
$header = 1 if eof;
}
当我运行这个脚本时,我只得到文件的标题,加上一个compiled.txt
条目。我还在 cmd 中收到以下消息:use of uninitialized $ARGV in concatenation <.> or string at concat.pl line 12
所以我想我做错了什么,$ARGV
根本没有使用。另外,$header
我应该使用其他东西而不是我来检索文本。
需要一些帮助!