As far as I can tell, there are 3 questions here.
Firstly:
From a unix-like prompt, just do
head -1 infile > outfile; cat tail -n+2 infile | sort -u >> outfile
But if you must use Perl (yay):
open IN,'<',$csvfile;
@data=<IN>;
close IN;
open OUT,'>',$newfile;
print OUT shift @data;
foreach my $line (@data) {$uniq{$line}=1;}
foreach my $line (keys %uniq) {print OUT $line;}
close OUT;
Please do the usual 'strict' and 'warning's stuff.
Secondly, you talk about putting the data into some sort of structure in memory...
Here I second cavac's request for a SSCCE
Thirdly, to create deep structures, mostly Perl will 'Just do it for you'.
E.G. I can do
$data{A}{B}{C}=[0,1]; $data{A}{X}=[5]; and I'll end up with the weird monstrosity I asked for:
DB<2> x \%data
0 HASH(0x555e18bb11b8)
'A' => HASH(0x555e184f6448)
'B' => HASH(0x555e18bb1218)
'C' => ARRAY(0x555e18bb1290)
0 0
1 1
'X' => ARRAY(0x555e18bb1278)
0 5
DB<3>
HTH!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.