我比较两个字符串,如(textid, citeid)
。如何声明字符串比较无限循环?
如果两个ID (textid, citeid)
相等对应uniqueid
应在textid
在整个文本引用部分取代。
MWE:
#!C:\Strawberry\perl\bin\perl
use strict;
use warnings;
use 5.010;
open(IN,"$ARGV[0]\.html")||die("Input LaTeX filename without .html extension\n");
local $/;
my $String_Match=<IN>;
my ($textid) = $String_Match =~ m/textid="(.*?)"/;
my ($citeid) = $String_Match =~ m/citeid="(.*?)"/;
my ($uniqueid) = $String_Match =~ m/ref uniqueid="(.*?)"/;
if ($textid eq $citeid)
{
if ($String_Match=~m/textid="(.*?)"/s)
{
$String_Match =~ s/textid="(.*?)"/textid="$uniqueid"/si;
}
}
print $String_Match;
字符串比较eq
功能不工作等(同时或做-同时)
上面MWE执行条件仅一次无限循环。但是我的所需输出textid
在整个文件中应该被替换为uniqueid
。
我的输入文件:
Text Citation Part
<xref textid="Narain:1982">1</xref>
<xref textid="Nasir:2012">2</xref>
<xref textid="Yao:2011">3</xref>
<xref textid="Cogley:1968">4</xref>
Reference Citation Part
<ref uniqueid="j_zna-2014-0260_ref_001"><citeid="Narain:1982"></ref>
<ref uniqueid="j_zna-2014-0260_ref_002"><citeid="Nasir:2012"></ref>
<ref uniqueid="j_zna-2014-0260_ref_003"><citeid="Yao:2011"></ref>
<ref uniqueid="j_zna-2014-0260_ref_004"><citeid="Cogley:1968"></ref>
我所需的输出文件:> out.txt
Text Citation Part
<xref textid="j_zna-2014-0260_ref_001">1</xref>
<xref textid="j_zna-2014-0260_ref_002">2</xref>
<xref textid="j_zna-2014-0260_ref_003">3</xref>
<xref textid="j_zna-2014-0260_ref_004">4</xref>
Reference Citation Part
<ref uniqueid="j_zna-2014-0260_ref_001"><citeid="Narain:1982"></ref>
<ref uniqueid="j_zna-2014-0260_ref_002"><citeid="Nasir:2012"></ref>
<ref uniqueid="j_zna-2014-0260_ref_003"><citeid="Yao:2011"></ref>
<ref uniqueid="j_zna-2014-0260_ref_004"><citeid="Cogley:1968"></ref>
请指点如何执行逻辑.....
故意输入和输出的空白区别? – simbabque
@simbabque我无法理解。你在说什么? – Vetri
我会逐行浏览文件,以textid作为关键字将数字存储在散列中,然后将所有唯一ID存储在那里,然后从中构建您的输出。你当然也可以像你这样做,然后抓住所有textids到数组等,但我会逐行找到更简单。 – bytepusher