林提取数据试图用PerlPerl中,正则表达式,从线
use strict;
use warnings;
# Set path for my.txt and extract datadir
my @myfile = "C:\backups\MySQL\my.txt";
my @datadir = "";
open READMYFILE, @myfile or die "Error, my.txt not found.\n";
while (<READMYFILE>) {
# Read file and extract DataDir path
if (/C:\backups/gi) {
push @datadir, $_;
}
}
# ensure the path was found
print @datadir . " \n";
以提取线的部分基本上在第一即时试图设置My.txt文件文件的位置。接下来即时通讯尝试读取它,并与正则表达式的部分行。即时得到的错误是:
Unrecognized escape \m passed through at 1130.pl line 17.
我看了看How can I grab multiple lines after a matching line in Perl?获得如何读取文件,并匹配中有一条线的想法,但即时通讯不是100%肯定,我这样做的权利或最好的办法。我似乎也产生错误:
Error, my.txt not found.
但是文件在指定的文件夹存在C:\备份\的MySQL \
未识别转义\米穿过在1130.pl线17已被分选这要归功于Mark Rushakoff和user275455的解决方案,我只需要在这里找不到my.txt文件的帮助,谢谢你说明了多种方法。 – perlnoob 2010-04-09 16:19:09
到目前为止,我已经有几乎所有我需要的答案,我能够修复前面提到的错误,但是现在我似乎无法从它读取的行中删除DataDir,我尝试使用“pop”并读取数组中的我读取文件的方式也一样,但还没有奏效。 – perlnoob 2010-04-09 22:45:37