Alright, so the following is a portion of the data set I am using, and following that is the format I would like it to eventually look like:
DATA SET 012345 NA13333 C C 012345 NA13334 F F 012345 NA13335 E F 012346 NA13333 U U 012346 NA13334 I I 012346 NA13335 Y O IDEAL OUTCOME **note the spacing comes out weird, SORRY! There is a si +te number above every pair of letters. SITES 012345 012346 NA13333 C C U U SITES 012345 012346 NA13334 F F I I SITES 012345 012346 NA13335 E F Y O
***** The code I am using again is:
#!/usr/bin/perl use strict; my $inFile = 'fanca.txt'; open (IN, $inFile) or die "open $inFile: $!"; my %user; while (my $line = <IN>) { next unless $line =~ m{^(\S+) (\d+) (.*)}; my ($site, $userID, $data, $data2) = ($1, $2, $3, $4); $user{$userID}{$site} = $data, $data2; } close(IN) or die "close $inFile: $!"; my $outfile = "parsingoutput_for_fanca.txt"; open(REPORT, ">$outfile") or die "open >$outfile: $!"; foreach my $userID (sort {$a <=> $b} keys %user) { my %sites = %{$user{$userID}}; my $line1 = 'SITES'; my $line2 = "$userID"; while (my ($site, $data, $data2) = each %sites) { $line1 .= ' ' x (length($line2)-length($line1)); $line2 .= ' ' x (length($line1)-length($line2)); #add on next site $line1 .= ' '. ' ' . $site; $line2 .= ' '. ' '. $data . ' ' . ' '. $data2; } print REPORT $line1 . "\n"; print REPORT $line2 . "\n"; print REPORT "\n"; } close (REPORT) or die "close $outfile: $!";

In reply to Re^4: Modifying a regex by Anonymous Monk
in thread Modifying a regex by seni

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.