這裏是一個字符串Perl的字符串格式化
[移動] [來源] [目標]
現在我想移動 「移動」, 「源」, 「目標」 到變量。
這是我的代碼提前
#Try grab the "move" part.
$data = "[ Move ] [ Source ] [ Destination ]"
$start = index($data, '[') + 2;
$end = index($data, ']') - 2; #The +- 2 is to get rid of the spaces
$cmd = substr $data, $start, $end; #This does not work. No idea why.
$data = substr $data, $end;
$start = index($data, '[') + 2;
$end = index($data, ']') - 2;
$source = substr $data, $start, $end;
$data = substr $data, $end;
$start = index($data, '[') + 2;
$end = index($data, ']') - 2;
$destination = substr $data, $start, $end;
感謝。
要了解原因,請參見[substr'函數的文檔](http://search.cpan.org/~rjbs/perl-5.12.3/pod/perlfunc.pod#substr) – mob 2011-03-07 15:40:50
爲了更好的方法,請查看[正則表達式](http://search.cpan.org/perldoc?perlretut)。 – mob 2011-03-07 15:42:12
正在閱讀文檔,但找不到有用的東西。 此外,我與正則表達式鬥爭。 – Krayons 2011-03-07 15:50:27