I have written a simple perl script (which works just fine) to open csv file, skip the first two lines of a header and format the columns from: 400;0,34567; to --> 400 0.34567 (change semicolon to space & comma to dot) I would appreciate your ideas on how to improve the following code:
#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new; open (CSV, "<File_name.csv") or die $!; while (<CSV>) { next if (1 .. 2); $_ =~ s/\;/ /g; $_ =~ s/,/\./g; if ($csv->parse($_)) { my @columns = $csv->fields(); print "@columns\n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV;
Somehow I have a feeling that this code is not efficient but it works. Is it worth to improve it or just use it as it is? I know it is possible to do this simple character replacement directly in vim using sed or with awk but I want to use Perl instead. Thank you!
In reply to ideas on how to improve existing code by trolis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |