2025年2月20日 星期四

計算table裡面的最大值 最小值 平均值

#!/usr/bin/perl use strict; use warnings; #檔案路徑 (請自行修改成正確路徑) my $filename = $ARGV[0]; my @numbers; #檢查檔案是否存在 unless (-e $filename) { die "檔案 $filename 不存在! \n"; } #讀取檔案內容 open (DATA, "<$filename"); while (){ chop $_; $_ =~ s/[",\\();a-zA-Z]//g; print "$ \n"; my @ary=split(" ",$_); push @numbers, @ary; } ## 計算最大值、最小值和平均值 my $max = (sort { $b <=> $a } @numbers)[0]; my $min = (sort { $a <=> $b } @numbers) [0]; my $sum =0; $sum += $_ for @numbers; my $avg = $sum / @numbers; ## 輸出結果 print "最大值: $max\n"; print "最小值: $min\n"; print "平均值: $avg\n"; close (DATA); 使用方式 perl max_min_avg.pl riseC 結果: 最大值:0.00323131 最小值: 0.00226739 平均值:0.002983495 riseC: "0.00264617, 0.00237069, 0.00230644, 0.00228424, 0.00227416, 0.00227032, 0.00226836, 0.00226739", "0.00322831, 0.00323131, 0.00316939, 0.00283283, 0.0025619, 0.00242233, 0.00235136, 0.002317", \ "0.00322562, 0.00322585, 0.00322684, 0.00321483, 0.00300823, 0.0026767, 0.00248122, 0.00238", "0.00322181, 0.00322257, 0.0032231, 0.00322229, 0.00322081, 0.00306827, 0.00272794, 0.00250753",\ "0.00321706, 0.00321843, 0.00321988, 0.00321986, 0.0032225, 0.0032165, 0.0030942, 0.00275446",\ "0.00321555, 0.00321851, 0.00321821, 0.00321952, 0.00322031, 0.00322318, 0.00321586, 0.00310252", "0.00321461, 0.00321901, 0.00321834, 0.00321678, 0.00321843, 0.00322075, 0.00321996, 0.00321428", "0.00321823, 0.00321797, 0.00321929, 0.0032173, 0.00321809, 0.00321879, 0.00321988, 0.00321961"

2025年1月19日 星期日

保留pin RETN{} block 跟mega_ 參數

#!/usr/bin/perl use strict; use warnings; # 檔案路徑 my $input_file = 'input.txt'; # 請將 'input.txt' 替換為你的檔案名稱 my $output_file = 'output.txt'; # 讀取檔案內容 open my $in_fh, '<', $input_file or die "無法打開檔案 $input_file: $!"; my @lines = <$in_fh>; close $in_fh; # 處理檔案內容 my $inside_block = 0; my @filtered_lines; foreach my $line (@lines) { if ($line =~ /pin \("RETN"\) \{/) { $inside_block = 1; # 開始進入區塊 } if ($inside_block || $line =~ /mega_/) { push @filtered_lines, $line; } if ($inside_block && $line =~ /xRxFxxx/) { $inside_block = 0; # 結束區塊 } } # 寫入處理後的內容到新檔案 open my $out_fh, '>', $output_file or die "無法創建檔案 $output_file: $!"; print $out_fh @filtered_lines; close $out_fh; print "已處理完成,結果存入 $output_file\n";

計算altos_veclist裡面有幾個vector並把數量寫在下面

#!/usr/bin/perl use strict; use warnings; # 檔案路徑 my $input_file = 'input.txt'; # 請將 'input.txt' 替換為你的檔案名稱 my $output_file = 'output.txt'; # 讀取檔案內容 open my $in_fh, '<', $input_file or die "無法打開檔案 $input_file: $!"; my @lines = <$in_fh>; close $in_fh; # 處理檔案內容 my @updated_lines; foreach my $line (@lines) { push @updated_lines, $line; #if ($line =~ /altos_veclist\(.*?\)/) { if ($line =~ /altos_veclist/) { # 計算 " 包住的字串總數 my $count = () = $line =~ /".*?"/g; # 在其下一行添加結果 push @updated_lines, "// 字串總數: $count\n"; } } # 寫入處理後的內容到新檔案 open my $out_fh, '>', $output_file or die "無法創建檔案 $output_file: $!"; print $out_fh @updated_lines; close $out_fh; print "已處理完成,結果存入 $output_file\n";

標籤