in reply to Argument "" Isn't numeric in numeric eq (==)
efficiency, but for the cases you see in @all, it works. Assumptions are that there will never be a "0"(zero)
value in any position, that your data will always have an even number of test values in each test case(3 per line?).
I had though that the 'defined' function would work, but it does not. Also, in the cases where there are empty values
in your data following defined values, the array does not even pick the empty values up. The case where the first test
value pair in the line are blank (,,1,2,,), is what makes the matching necessary down in the while loop. Those first two
values actually come in as empty strings...
Hope this is of some use to you... it sure ain't pretty... lol...#!/usr/bin/perl use strict; use warnings; my (@all,$line,$fail,$success,$f,$s,$lc,$sc); push(@all, "1,1,,,,"); push(@all, "3,4,1,1,,"); push(@all, "1,1,1,1,,"); push(@all, "5,6,3,4,1,2"); push(@all, "1,1,1,1,1,1"); push(@all, "1,2,,,,"); push(@all, ",,1,2,,"); $lc = 0; #line count $sc = 0; #success count foreach $line (@all) { my @data = split(",", $line); $lc ++; $f = 0; $s = 1; while ($f < (scalar @data)) { if ($data[$f] !~ m/[0-9]/) { $f = $f + 2; $s = $s + 2; next; }; if ($data[$s] !~ m/[0-9]/) { $f = $f + 2; $s = $s + 2; next; }; if ($data[$f] + $data[$s] != 2) { $fail = 1; $success = 0; } else { $success = 1; $fail = 0; $sc ++; print "Line $lc contains a success, $sc successes found th +us far...\n" } $f = $f + 2; $s = $s + 2; } }
|
|---|