2007年3月18日 星期日

[Perl] 檔案處理與簡單的判斷例子





# 檔案位置


$wwwshow="/home/user/public_html/test.htm";





# 開檔失敗,則會換成執行後面那段話


open(FD_In,$wwwshow) || die "Can't open file: $!" ;





while( defined($LineIn = ) ){


# 若有出現溫度跟F的符號,進行切字的笨手段


if($LineIn =~ /°F/){


# get thermometer F;


@tmp01Line = split($splittoken01_a,$LineIn);


@tmp02Line = split($splittoken01_b,$tmp01Line[1]);


$thermometerF{$location[$i]} = $tmp02Line[0];


$thermometerC{$location[$i]} = ($thermometerF{$location[$i]} - 32) * 5 / 9;


# get thermometer Feel Like F;


@tmp01Line = split($splittoken02_a,$LineIn);


@tmp02Line = split($splittoken02_b,$tmp01Line[1]);


$thermometerFeelLikeF{$location[$i]} = $tmp02Line[0];


$thermometerFeelLikeC{$location[$i]} = ($thermometerFeelLikeF{$location[$i]} - 32) * 5 / 9;


# get weather


@tmp01Line = split($splittoken03_a,$beLine);


@tmp02Line = split($splittoken03_b,$tmp01Line[1]);


$weather{$location[$i]} = $tmp02Line[0];


}elsif($LineIn =~ /$splittoken04/){


@tmp01Line = split($splittoken04_a,$LineIn);


@tmp02Line = split($splittoken04_b,$tmp01Line[1]);


$updatetime{$location[$i]} = $tmp02Line[0];


# last 指的就是 C/C++ 中的 break


last;


}


$beLine = $LineIn;


}


close(FD_In);


# 把檔案刪掉


unlink($wwwshow);





# 開檔準備寫入


open(WEATHER,">$wwwshow") || die "Can't open file: $!" ;


print WEATHER "Weather Information\n";


close(WEATHER);




沒有留言:

張貼留言