I just did the following while playing around with this. There is a lot to be desired regarding elegance and

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...

#!/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; } }
Hope this is of some use to you... it sure ain't pretty... lol...
...the majority is always wrong, and always the last to know about it...
Insanity: Doing the same thing over and over again and expecting different results.

In reply to Re: Argument "" Isn't numeric in numeric eq (==) by wjw
in thread Argument "" Isn't numeric in numeric eq (==) by ler224

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.