in reply to print last array element without a new line
Unless you're messing with $/ or $\, chomp will remove the newline, and there cannot possibly be two of them.
Your code does exactly what you say you want it to do.
while(<DATA>){ chomp(my $record = $_); my @field = split /\,/, $record; print "$field[0],$field[10],$values[0],$field[1],$field[2]\n"; } __DATA__ a,b,c,d,e,f,g,h,i,j,k a,b,c,d,e,f,g,h,i,j,k
a,k,,b,c a,k,,b,c
There's an empty field, but that's because I didn't give $values[0] a value. (In fact, I would get a warning with use warnings;.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: print last array element without a new line
by sy (Initiate) on Oct 19, 2011 at 19:50 UTC | |
by onegative (Scribe) on Oct 19, 2011 at 20:14 UTC | |
by ikegami (Patriarch) on Oct 19, 2011 at 23:02 UTC | |
by sy (Initiate) on Oct 19, 2011 at 21:05 UTC |