Hej Monks,

I have a following data structure :

UID= UID=FRLARS UID=ANJA08 FNA= FNA=Fredrik FNA=Anja ENA=Exp-pri ENA=Larsson ENA=Daun PRE=(0117) PRE=(0117) PRE=(0117) NYTT=23400 NYTT=23403 NYTT=23404 PRI1=Nej FOR1=Nej DOL1=Nej CMG1=Ja MEX1=Nej PRI2=Nej FOR2=Nej DOL2=Nej CMG2=Ja MEX2=Nej PRI3=Nej FOR3=Nej DOL3=Nej CMG3=Ja MEX3=Nej
as a result of a web form. Now, is it possible to get this data out in a "csv" format having in mind that number of records can differ which means that "x" in last part (PRIx, FORx, DOLx, CMGx, MEXx) will increase depending on how many UIDs there are ?

I've tried with following :
my @entries; my $previouskey = ""; open (KOF, "<$konfil") or die "Kan inte \xF6ppna filen $konfil"; open (NYF, ">$nyfil") or die "Kan inte \xF6ppna filen $nyfil"; flock (NYF,2) or die $!; my $offset = 0; while(<KOF>) { chomp; $value =~ s/^\s*(\S*)\s+$/$1/; unless ($key eq $previouskey || $previouskey eq "") { $offset = 0; } $previouskey = $key; $entries[$offset]{$key} = $value; $offset++; } my @sorted = sort { $a->{'NYTT'} <=> $b->{'NYTT'} } @entries; my $pers =0; foreach my $e (@sorted) { print NYF ($e->{'UID'}, "|", $e->{'FNA'}, "|", $e->{'ENA'}, "|", $ +e->{'PRE'}, "|", $e->{'NYTT'}, "\n") if( $e->{"UID"} ne "" || $e->{"F +NA"} ne "" || $e->{"ENA"} ne ""); $pers++ if ($e->{"UID"} ne ""); } close KOF; close NYF;
and it seems to work fine, but I just don't know how to add now last part that changes numbers in the name.

Thanks in advance for your help


In reply to Manipulating data structure by SerZKO

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.