我必須讀取a file中的行並將它們存儲到Perl中的哈希中。許多這些行在開始時都有特殊的字符序列,我需要在存儲之前將其刪除。這些字符序列是如何從Perl中的字符串開頭刪除字符序列列表?
| || ### ## @@||
例如,如果是||https://ads
,我需要得到https://ads
;如果###http
,我需要得到http
。
我需要排除這些字符序列。我想通過將所有字符序列排除在數組中,然後檢查該行是否以這些字符序列開頭並刪除這些字符序列來完成此操作。什麼是這樣做的好方法?
據我已經爲:
our $ad_file = "C:/test/list.txt";
our %ads_list_hash =();
my $lines = 0;
# List of lines to ignore
my @strip_characters = qw /| || ### ## @@||/;
# Create a list of substrings in the easylist.txt file
open my $ADS, '<', $ad_file or die "can't open $ad_file";
while(<$ADS>) {
chomp;
$ads_list_hash{$lines} = $_;
$lines ++;
}
close $ADS;
我需要添加到每個行的開頭刪除@strip_characters
如果其中任何存在的邏輯。
把所有的字符表達代替,然後用它來代替(刪除)不想要的字符 – 2011-03-29 08:52:29