#!/usr/bin/perl
open (FILE, "<ARGV[0]") or die "Can't open $ARGV[0] file";
open(SAME_OUT,">same_out.h") pr die "Can't open same_out.h file";
my $i=0;
my $count=1;
my @file_cotent=();
#将文件按行为元素放入数组中方便处理
while (<FILE>){
push @file_count,$_;
}
foreach $tmp_name (@file_content){
$count=$count+1;
#因为我的文件内容都是 #define content 12; 我希望找到content相同的词,并输出
if($tmp_name =~ /#define\s([^\s]*)\s.*/){
$tmp_name=$1;
for ($i=$count; $i<@file_content;$i++){
if($file_content[$i] =~ /#define\s([^\s]*)\s.*/){
$tmp_name=$1;
if($tmp_name_same eq $tmp_name){
print SAME_OUT "$tmp_name_same\n";
}
}
}
}
close FILE;
close SAME_OUT;
标签:tmp,count,name,same,perl,content,查找,file From: https://www.cnblogs.com/xiaoyong5/p/17111917.html