-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeparts.pl
47 lines (38 loc) · 971 Bytes
/
mergeparts.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use Text::CSV;
use File::Basename;
my $csv = Text::CSV->new ( ) # should set binary attribute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
my %parts=();
foreach my $file (@ARGV)
{
my $prefix=(fileparse($file, qr/\.[^.]*/))[0];
open(FILE, "<$file") or die("Unable to open $file: $!");
while(my $row = $csv->getline( *FILE ))
{
my ($ref, $quant, $name, $description, $package, $digikeyPart) = @{$row};
if ($ref eq "Reference") {next;}
my @refs=split(";", $ref);
foreach my $x (0..$#refs)
{
$refs[$x]="$prefix-$refs[$x]";
}
$ref=join(" ", @refs);
if (defined($parts{$digikeyPart}))
{
my ($refs, $total)=@{$parts{$digikeyPart}};
$refs=$refs." ".$ref;
$total+=$quant;
$parts{$digikeyPart}=[$refs, $total];
}
else
{
$parts{$digikeyPart}=[$ref, $quant];
}
}
close(FILE);
}
for my $digikeyPart (sort keys %parts)
{
my ($refs, $total)=@{$parts{$digikeyPart}};
print("$refs,$total,$digikeyPart\n");
}