I'm very new to Perl so please excuse the simple question. I'm processing CSV files and for each record I split the record by comma and then printout a subset of fields in rearranged form. My problem is that I cannot print the LAST element of an array without also getting a newline. This is a problem because I want the last array element to be in the middle of a new record. I've tried using chomp (multiple times) on the input line, the array, or the array element, and I've consulted much documentation to no avail. Can someone offer and explanation and fix that suits a beginning programmer? For example, in the simplified but representative code below I get an unwanted new line after $field10
open(SOURCE, "<", $filename) or die "Can't open $filename"; while(<SOURCE>){ chomp(my $record = $_); my @field = split /\,/, $record; #split record into fields by comm +as print DATAOUT "$field[0],$field[10],$values[0],$field[1],$field[2] +\n"; }
In reply to print last array element without a new line by sy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |