我比較兩個字符串,如(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