Hi Monks,

I have a question about re-organising entries. Currently ,I have files with entries that look like this:

1 SP_85(IS33, qqq), SP_155(IS33eee) spr_111(ISyyy33, qqq), spr_1 +71(IS33eee) 2 SP_83(S3 , jgjg), SP_32(IS33, jhdjdjd) spr_113(Stty3 , jgjg), +spr_1881(IS33, jhdjdjd) 3 SP_78(3jmdsjkdej), SP_66(IShbdhdhd33) spr_115(3jmhhggggdsjkdej +), spr_1551(IShbdhdjjjhd33), spr_88881(Iyt33ff), spr_145411(Iddd3ff) 4 SP_77(3jmdsjkdej), SP_1485(Idhd33ff) spr_116(3jmdhhhhhsjkdej), + spr_17781(Idhdhhtytyt33ff)

How do I re-organise them so that all entries with a similar name will be in the same column

Here is my desired output:

1 SP_85(IS33, qqq) spr_111(ISyyy33, qqq) 1 SP_155(IS33eee) spr_171(IS33eee) 2 SP_83(S3 , jgjg) spr_113(Stty3 , jgjg) 2 SP_32(IS33, jhdjdjd) spr_1881(IS33, jhdjdjd) 3 SP_66(IShbdhdhd33) spr_115(3jmhhggggdsjkdej) 3 SP_66(IShbdhdhd33) spr_1551(IShbdhdjjjhd33) 3 - spr_88881(Iyt33ff) 3 - spr_145411(Iddd3ff) 4 SP_77(3jmdsjkdej) spr_116(3jmdhhhhhsjkdej) 4 SP_1485(Idhd33ff) spr_17781(Idhdhhtytyt33ff)

Please bear in mind that I have hundreds of columns and thousands of rows

The code i have tried implementing so far:

my $columnFile = q{re-organized.txt}; open my $columnFH, q{<}, $columnFile or die qq{open: < $columnFile: $!\n}; my @results; while ( <$columnFH> ) { my @cols = split; foreach my $idx ( 0 .. $#tests ) { foreach my $subidx ( 0 .. $#{ $tests[ $idx ] } ) { my @posns = split m{,}, $tests[ $idx ]->[ $subidx ]; $results[ $idx ]->[ $subidx ] ++ if scalar @posns == grep { q{z} eq $cols[ $_ ] } @posns; } } } close $columnFH or die qq{close: < $columnFile: $!\n};

Thanks,

$new_guy


In reply to Re-organising entries by $new_guy

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.