I have a CSV input file (input.csv) with numbers looking like:
1.34,7.56,4.57,6.7,4.9, 3.4,5.7,5.4,........
I want to edit the file and insert numbers and a colon between fields like;
1:1.34 2:7.56 3:4.57 4:6.7 5:4.9 6:3.4 7:5.7 8:5.4..........
Here is my script:
#!/usr/bin/perl
use strict;
use warnings;
#Opening the CSV file
my $csv_file = "input.csv";
open (my $fh, "<", $csv_file) or die "Cannot open '$csv_file': $! ";
#parsing
while (my $lines = <$fh> ) {
chomp $lines;
my @features = split (',', $lines);
print "$lines \n";
}
#inserting numbers
for ( my $x = 1; $x <= 1371; $x++ ){
print $x . ":" . $features[$x-1];
}
I get an error: Global symbol "@features" requires explicit package name at script_T.pl line 23.