Here's one way of doing the actual parsing bit (ignoring headers, reading from __DATA__ and printing to the screen for simplicity):

use strict; use warnings; my $name_id = 0; my %seen_name; <DATA> for 1 .. 5; # Remove headers while ( my $line = <DATA> ) { next unless $line =~/\w/; if ( $line =~ /Name/ ) { $name_id = parse_name( $line ); } else { my @tmp = split ' ', $line; shift @tmp; my $date = shift @tmp; print join ',', $name_id, $name_id, @tmp, $date; print "\n"; } } print "\n________Names file________\n\n"; for my $key ( sort { $seen_name{$a} <=> $seen_name{$b} } keys %seen_na +me ) { my @names = split /,/, $key; my $val = $seen_name{$key}; print join ",$val,", @names, "\n"; } sub parse_name { my $line = shift; my $name = join ',', ( split ' ', $line )[1, 3]; if ( $seen_name{$name} ) { $name_id = $seen_name{$name}; } else { $name_id += 1; $seen_name{$name} = $name_id; } return $name_id; }

In reply to Re: Space delimted to CSV, Index and data extraction loop by Not_a_Number
in thread Space delimted to CSV, Index and data extraction loop by SixShot

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.