in reply to Splitting on tabs then removing extra white space with map
The general rule when it comes to parsing character separated data is: Don't. Use a module instead. In this case Text::xSV is most likely appropriate. Consider:
use strict; use warnings; use Text::xSV; my $xsv = Text::xSV->new (sep => "\t", fh => *DATA); while (my @row = $xsv->get_row ()) { map {s/\s+$//; s/^\s+//} @row; print ">", join ("< >", @row), "<\n"; } __DATA__ 0.000 12 0.232 13 11 text that can have space 1.000 13 0.534 14 12 More text that would be ok 2.000 14 0.876 15 13 yet more text
Prints:
>0.000< >12< >0.232< >13< >11< >text that can have space< >1.000< >13< >0.534< >14< >12< >More text that would be ok< >2.000< >14< >0.876< >15< >13< >yet more text<
Update: altered code to use __DATA__ rather than heredoc.
|
|---|