Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

It may be best to work on the A.txt and B.txt data sets you showed. If you can create a script to generate the ORed results of those two matrices, then it's most likely that script will work with larger matrices.

First, always begin your scripts with either:

use strict; use warnings;


use Modern::Perl;

I prefer the latter, since it includes the former two pragmas--among other things.

You can use File::Slurp qw/read_file/; to read a file's contents into an array. The foreach() takes a list or array--not a scalar, like you've done. That would account for some of the errors.

Here's one way to approach the problem:

  1. Read both matrix files into arrays.
  2. The first element (row 0) of each array is identical, as it contains the column titles. Grab those and create the title string (like in the first script, but w/o sorting), and move to the next rows (1 .. n) of the two arrays.
  3. Split each row (1 .. n) of the two arrays into their elements, placing those elements into two element arrays. The zeroth element of these arrays contains the row label.
  4. Do an OR comparison between the two element arrays (1 .. n), and build an OR-result array for the table.
  5. Finally, build the table and print it.

The scripting that produced the first table should help with reading files and building the table.

Step through this scripting process, and then share what you've completed. A script can be created to produce the ORed output you need; it'll just take a little more work...

In reply to Re^7: A complicated file parsing and 2D array/matrix problem. by Kenosis
in thread A file parsing and 2D array/matrix problem. by zing

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [oiskuu]: I must watch Police Academy again sometime.
    [Discipulus]: thanks all
    [LanX]: ?
    [LanX]: disc+ you can also modify this  approach if you don't want recursions

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (8)
    As of 2018-03-19 11:29 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (239 votes). Check out past polls.