Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

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

How about this:

use strict; use warnings; my $letters = <DATA>; my @letters = $letters =~ /\w+/g; my %out; while(<DATA>) { next if /SampleID/; chomp; my @recs = split /\s+/; my $ctr = 2; for my $letter (@letters) { $out{$letter} .= "$letter\t".(join "\t", @recs[0,1,$ctr++])."\n"; } } for my $letter (@letters) { print $out{$letter}; } __DATA__ A C F SampleID Time ObsConc ObsConc ObsConc 5 24 2.27E+06 687.02 32521.94 5 168 1.92E+06 525.02 22198.44 5 12 2.94E+06 896.39 41331.61 5 -0.5 2.23E+06 942.34 40616.49 5 8 4.03E+06 1371.32 45863.69 6 24 1.02E+06 1057.89 46341.04 6 168 3.14E+06 4987.32 42166.08

This assumes that the line with A C F is potentially variable and due to change. Otherwise it could be further simplified by hardcoding it. It also assumes that you always repeat the first two columns.

It builds the output fully in memory, which might be a problem if you have HUGE input. In order to minimize memory consumption, one could use temporary files for each of the letters and merge them later.

UPDATE: No statement about the "ugliness" of this or other code is implied...

In reply to Re: format conversion, please help by hdb
in thread format conversion, please help by david_lyon

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
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (3)
    As of 2018-08-17 07:05 GMT
    Find Nodes?
      Voting Booth?
      Asked to put a square peg in a round hole, I would:

      Results (174 votes). Check out past polls.