#!/usr/bin/perl &readDataBase; #------------------------ $test1=20220040200333; &module_identify($test1); print "$test1 is ided as $ided\n"; ==> 20220040200333 is ided as 1 3 20 -2 100 $test1=20220990291318; &module_identify($test1); print "$test1 is ided as $ided\n"; $test1=20220040200020; &module_identify($test1); print "$test1 is ided as $ided\n"; #--------------readin module data base------------ sub readDataBase { open(IN,"../SCT/module_DB.txt"); @file = ; #ここで配列fileに1行ずつ読んでいる close(IN); print "input[0]: @file[0]\n"; ==> input[0]: 20220040200012 0 3 55 -6 2 12 47 28 23 print "input[1]: @file[1]\n"; ==> input[1]: 20220040200013 0 3 48 -6 2 811 2 36 $i=0; foreach $xxx (@file){ (@id[$i],$w,@ed[$i],@layer[$i],@phi[$i],@eta[$i]) = split(/ /,$xxx); $add=1; if($ed[$i]==0) {$add=3;} @layer[$i] += $add; @ed[$i] = (@ed[$i]+2)/2; if($i<10) {print "$i: @id[$i] = @ed[$i] @layer[$i] @phi[$i] @eta[$i]\n";}  ==> 0: 20220040200012 = 1 6 55 -6 $i++; } print "Module data base were read-in for $i modules\n";; ==> Module data base were read-in for 4088 modules #--------------readin CiS------------ open(IN,"../SCT/CiS.txt"); @CiS = ;    ==> 配列@CiSにデータ(20220270300262 203765760 2 1 10 7など)が入っている close(IN); #print "@CiS\n"; $iCiS=0; foreach $xxx (@CiS){ (@idCiS[$iCiS]) = split(/ /,$xxx); / /で分けた後に1列目を@idCiSに格納している #print "$iCiS: @idCiS[$iCiS] \n"; $iCiS++; } print "CiS module data were read-in for $iCiS modules\n"; ==> CiS module data were read-in for 496 modules #--------------readin <100> modules------------ open(IN,"../SCT/100.txt"); @id100 = ; ==> 配列@id100にデータ(20220040200555など)が入っている close(IN); #print "@id100\n"; $i100=0; foreach $xxx (@id100){ #print "$xxx"; $i100++; } print "<100> module data were read-in for $i100 modules\n"; #------------------------ } sub module_identify { ($yyy) = @_; $type=111; foreach $xxx (@idCiS) {if($xxx == $yyy) {$type = 200;} } foreach $xxx (@id100) {if($xxx == $yyy) {$type = 100;} } my $k=0; foreach $xxx (@id) { if($xxx == $test1) { $ided = sprintf("%d %d %d %d %d", @ed[$k], @layer[$k], @phi[$k], @eta[$k], $type); } $k++; } } -------------------------------------------- $ perl sub.pl input[0]: 20220040200012 0 3 55 -6 2 12 47 28 23 input[1]: 20220040200013 0 3 48 -6 2 811 2 36 0: 20220040200012 = 1 6 55 -6 1: 20220040200013 = 1 6 48 -6 2: 20220040200014 = 1 6 35 -6 3: 20220040200016 = 1 6 54 -5 4: 20220040200017 = 1 6 48 -5 5: 20220040200019 = 1 6 24 5 6: 20220040200020 = 1 6 40 -5 7: 20220040200021 = 1 6 54 -4 8: 20220040200022 = 1 5 47 -5 9: 20220040200023 = 1 6 54 -3 Module data base were read-in for 4088 modules CiS module data were read-in for 496 modules <100> module data were read-in for 92 modules 20220040200333 is ided as 1 3 20 -2 100 20220990291318 is ided as 0 8 12 1 200 20220040200020 is ided as 1 6 40 -5 111