ので、私のファイルは次のようになります。このファイル操作はどのようにしてperlで行いますか?
--some comments--
--a couple of lines of header info--
comp:
name: some_name_A
type: some_type
id: an id_1
owner: who owns it
path: path_A to more data
end_comp
comp:
name: some_name_B
type: some_type
id: an id_2
owner: who owns it
path: path_B to more data
end_comp
私はを何をしたいか:名前フィールドから名前を取得し、それは我々が検索したい名前のいずれかと一致するかどうかを確認(すでに配列で提供)、パスを取得した後、そのパスに行き、いくつかの力を行使して新しいidを取得し、現在のidを新しいidに置き換えます。
は私が(ちょうど擬似)を行っている:
@filedata = <read_file> #read file in an array
$names_to_search = join("|", @some_names);
while([email protected])
{
if($line =~ /comp:/)
{
$line = <next line>;
if($line =~ /name: $names_to_search/)
{
#loop until we find the id
#remember this index since we need to change this id
#loop until we find the path field
#get the path, go to that path, do some perforce commands and obtain new id
if(id is same as current id) no action required
else replace current id with new id
}
}
}
問題:私の現在の実装では、whileループ3のように持っています!これを行うにはより良い/効率的/優雅な方法がありますか?
ファイルに 'name'と同じ値を持つ2つのブロックがありますか? –
@JackManey、Nope :) – infinitloop