Reputation: 55
Hey guys this i've got to replace a certain header colum with a new one note it's just the header not anything else in the CSV file
Naam,Functie,Functiecode,SMS,telefoonnr. 1,telefoonnr. 2,telefoonnr. 3,,overig
The header of my files. and telefoonnr. 1,telefoonnr. 2,telefoonnr. 3
Have to be replaced with
telefoonnr1,telefoonnr2,telefoonnr3
Upvotes: 0
Views: 117
Reputation: 6204
Here's another option:
use strict;
use warnings;
my $newHeader = 'Naam,Functie,Functiecode,SMS,telefoonnr1,telefoonnr2,telefoonnr3,,overig';
while (<>) {
$_ = "$newHeader\n" if $. == 1;
print;
}
Usage: perl script.pl inFile [>outFile]
The last, optional parameter directs output to a file.
Hope this helps!
Upvotes: 1
Reputation: 561
You could use Tie::Array::CSV
use Tie::Array::CSV;
my $filename = '/path/to/file.csv';
tie my @file, 'Tie::Array::CSV', $filename;
$file[0] = ['Naam','Functie','Functiecode','SMS','telefoonnr1','telefoonnr2','telefoonnr3',,'overig'];
untie @file;
Upvotes: 0