string2:string4:totalName
Here are my Rules:
So given a file with values that match the bullet list above, if the Array looks like this:
string2:string4:totalName
Then the line "totalName,114" would get added to the end of the file.
If the Array looks like this:
string1:string4:string2:otherName
Then the line "otherName,148" would get added to the end of the file.
If the Array looks like this:
string7:string9:noName
Then no line at all would get added to the end of the file. My original code was buggy because if either one of the two elements was missing, it didn't create the Total row in the file. Also the requirements grew when I found I needed to be able to combine more than two rows of the file.
Just wondering if there is a preferred logical approach to matching 'lists' to other 'lists'? It feels like I may be doing this the hard way.open( FILE, '<', $sumOutPath ) or warn "!!! Cannot Open $sumOutPath !! +!\n"; @LINES = (); @LINES = <FILE>; my @LINES2 = @LINES; close FILE; # For each row we may need to foreach my $LINE (@LINES) { chomp $LINE; if (index($LINE, $rpcComboStatsSegments[0]) != -1) { ### This r +ow needs to be fixed to by a loop for all Stats if the first or 2nd i +sn't found. if($debug) { print "--->>> $LINE contains $rpcComboStatsSegmen +ts[0]\n"; } $combinedTotal = (split /,/,$LINE)[1]; if($debug) { print "Combined Total = $combinedTotal\n"; } foreach my $LINE2 (@LINES2) { chomp $LINE2; if($debug) { print "---->>>> full line $LINE2 and $rpcCombo +StatsSegments[1]\n"; } if (index($LINE2, $rpcComboStatsSegments[1]) != -1) { if($debug) { print "---->>>> $LINE2 contains $rpcComboSt +atsSegments[1]\n"; } $combinedTotal = $combinedTotal+(split /,/,$LINE2)[1]; #print "Combined Total now = $combinedTotal\n"; #we want to Append a Total RPC statistic to the end of t +he SummaryOut file open( FILE, '>>', $sumOutPath ) or warn "!!! Cannot Open + $sumOutPath !!!\n"; print FILE $rpcComboStatsSegments[2] . "," . $combinedTo +tal . "\n"; close FILE; last; } } } }
In reply to flexible string value matching in lists by archeman2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |