Consider using a regex that captures sets of two digits (or 'empties') separated by a comma, as tuples:

use strict; use warnings; while ( my $line = <DATA> ) { print +( join ',', map "($_)", $line =~ /(\d*,\d*),?/g ), "\n"; } __DATA__ 1,1,,,, 1,2,,,, 3,4,1,1,, 1,1,1,1,, 5,6,3,4,1,2 1,1,1,1,1,1 ,,,,1,1 ,,1,2,, ,,1,1,1,2 ,,,,, 5,6,3,4,2,2

Output:

(1,1),(,),(,) (1,2),(,),(,) (3,4),(1,1),(,) (1,1),(1,1),(,) (5,6),(3,4),(1,2) (1,1),(1,1),(1,1) (,),(,),(1,1) (,),(1,2),(,) (,),(1,1),(1,2) (,),(,),(,) (5,6),(3,4),(2,2)

And then testing for '1,1' and '1,2' in each line:

use strict; use warnings; my ( $i, $success, $fail ); while ( my $line = <DATA> ) { $i++; my %tuples = map { $_ => 1 } $line =~ /(\d*,\d*),?/g; $success++ if exists $tuples{'1,1'}; $fail++ if exists $tuples{'1,2'}; } print "Total Lines: $i\nSuccess: $success\nFail: $fail\n"; __DATA__ 1,1,,,, 1,2,,,, 3,4,1,1,, 1,1,1,1,, 5,6,3,4,1,2 1,1,1,1,1,1 ,,,,1,1 ,,1,2,, ,,1,1,1,2 ,,,,, 5,6,3,4,2,2

Output:

Total Lines: 11 Success: 6 Fail: 4

BTW - You were off by one in all of your array indices. You had:

if((($f[1]==1)&&($f[2]==1))|| ...

when you meant:

if((($f[0]==1)&&($f[1]==1))|| ...

Hope this helps!

Edit: Updated to reflect the '1,2' "Fail" condition, which I failed to notice. Thank you, Jim.


In reply to Re: Argument "" Isn't numeric in numeric eq (==) by Kenosis
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.