Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If you can hold everything in memory, this should come close to doing what you want. It has the following assumptions/behviors:

  • Each row has the same number of whitespace delimited fields (columns).
  • Zeroes starting a column or ending a column are meant to be zeroes after patching.
  • #!/usr/bin/env perl use Modern::Perl; use Data::Dump qw(pp); my %cols; my @patch_cols = qw(2 3); while (<DATA>) { my @row = split; push @{$cols{$_}}, $row[$_] for (0..$#row); } for my $col (@patch_cols) { my @fwd = @{$cols{$col}}; my @bwd = reverse @fwd; for my $i (1..$#fwd) { $fwd[$i] = $fwd[$i-1] if $fwd[$i] == 0; $bwd[$i] = $bwd[$i-1] if $bwd[$i] == 0; } @bwd = reverse @bwd; $fwd[$_] == $bwd[$_] and $cols{$col}->[$_] = $fwd[$_] for (0..$#fw +d); } say pp(\%cols); say pp(\@patch_cols); __DATA__ 1 100 1 2 101 200 1 2 201 300 1 0 301 400 1 0 401 500 0 2 501 600 0 2 601 700 0 0 701 800 1 1 801 900 1 2

    Produces:

    { "0" => [1, 101, 201, 301, 401, 501, 601, 701, 801], "1" => [100, 200, 300, 400, 500, 600, 700, 800, 900], "2" => [1, 1, 1, 1, 1, 1, 1, 1, 1], "3" => [2, 2, 2, 2, 2, 2, 0, 1, 2], } [2, 3]

    In reply to Re: filling in the zeros...please help by jaredor
    in thread filling in the zeros...please help by david_lyon

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



    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-24 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found