我必須輸出行數爲「找到神奇數字」味精,找到每個神奇數字檢查神奇數字
我正在解析一個.C文件。
幻數基本上是
if(list == 5) // here 5 is magic number
for(int i = 0; i<6; i++) //here 6 is magic number
MY CODE
use strict;
use warnings;
my $input = $ARGV[0];
open(FILE, $input) or die $!;
my @lines = <FILE>;
my $count = 0;
foreach(@lines){
$count++;
if($_ =~ 'for\('){ # I want to check within for()
if($_ =~ '#####'){ # how do the check for numbers
print "magic number found at line:".$count;
}
}
elif($_ =~ 'if\('){ # I want to check within if()
if($_ =~ '#####'){
print "magic number found at line:".$count;
}
}
}
作爲幻數只存在於for循環,並且如果循環,所以想的,如果存在任何小數托架內,以檢查或十六進制值。
我認爲這是比'regex'檢查要複雜得多。如果每個子句在不同的行中都有'for'?或者是一個名爲'i345'而不是'i'的變量?只說幾個問題。 – Birei
@Birei是真的...... dnt想想那個,然後再做任何其他的方式 –
因此,讓我直截了當地說,你想解析C代碼,但是你從來沒有在你的問題中提過它?也許你應該? – TLP