Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何在Perl中解析文件中的一些文本_Regex_Perl_File_Parsing - Fatal编程技术网

Regex 如何在Perl中解析文件中的一些文本

Regex 如何在Perl中解析文件中的一些文本,regex,perl,file,parsing,Regex,Perl,File,Parsing,你好,我想用这样的结构解析文件。。。在名称之后:{}它可以是具有相同形式的其他事物。某物:{} --- NAMES: first_thing: {} second_thing: {} name: {} 谢谢你的回答 我想把它解析成这个表单 first_thing second_thing name 这可能会有帮助 preg_match_all('/^(\w+):\s(.*?)$/m', $input, $output, PREG_SET_ORDER); 在windows

你好,我想用这样的结构解析文件。。。在名称之后:{}它可以是具有相同形式的其他事物。某物:{}

--- 
NAMES: 
  first_thing: {}

  second_thing: {}

  name: {}
谢谢你的回答

我想把它解析成这个表单

first_thing
second_thing
name
这可能会有帮助

preg_match_all('/^(\w+):\s(.*?)$/m', $input, $output, PREG_SET_ORDER);
在windows上:

perl -ne "print qq{$1\n} if /^\s+ (\w+)/x" file

无法以书面形式回答您的问题。例如,不清楚您试图从文件中解析什么,以及它应该如何构造。请澄清您的问题。另外,请告诉我们您尝试过的事情,或者说明您为获得工作愿意支付的金额。我想删除前2行,其他行我只需要一个不带括号的单词(:)冒号在EOF at-e第1行之前的任何地方都找不到字符串终止符“'。
my$input=“input.txt”;my@myarray=`perl-ne'打印qq{$1\n}如果/^\s+(\w+)/x“$input
;`谢谢你的回答。我也可以问你如何将它转换为另一个文件吗?myarray to output.txt fo exampleperl-ne“print qq{$1\n}if/^\s+(\w+)/x”file>output.txOK这个我知道,但是如何从其他文件调用它。。。不是从terminalUndefined子例程&main::preg_match_在test.pl第5行调用。
#/usr/bin/perl my$input=“$input.txt”;my$output=“$output.txt”;如果(preg_match_all('/^(\w+):\s(.*?$/m',$input,$output,preg_SET_ORDER)){print“SUCCESS”;}否则{print“FAILED”;}
很抱歉,该函数是PHP函数,我没有意识到您要求的是perl,无论如何,请在perl
@output=($input=~m/^(\w+):\s(.*$/)中尝试一下
perl -ne "print qq{$1\n} if /^\s+ (\w+)/x" file