#!/usr/bin/perl use strict; use warnings; # config my $inPath = "internet.csv"; my $outPath = "internet_artikelstamm.csv"; my $outHeader = 'status;artnr;name;short_description'; my %defaultVal = ('status' => 'Aktiviert'); # / config open (my $inFH, "<", $inPath) || die $!; open (my $outFH, ">", $outPath) || die $!; print $outFH "$outHeader\n"; chomp (my $firstRow = <$inFH>); my @inHeader = split /;/, $firstRow; while (<$inFH>) { chomp($_); my @inRow = split /;/, $_; my %outRow; $outRow{$_}= ($defaultVal{$_} // '') for (split /;/, $outHeader); for my $col (0..@inHeader-1) { $outRow{$inHeader[$col]} = $inRow[$col] if defined ($outRow{$inHeader[$col]}); } next if $outRow{'name'} =~ /\*\*/; my @printRow; push @printRow, $outRow{$_} for split /;/, $outHeader; print $outFH (join ";", @printRow) . "\n"; } close $inFH or die $!; close $outFH or die $!;