I'm parsing a file that's tab-delimited, except it has a bunch of extra white space around the values that I'd like to remove. I can't just use split on white space, because there's mixed values (some floats, that I'd like to remove the white space from, and some strings that can have white space).
My first attempt was this:
#!/bin/perl use warnings; use strict; use Data::Dump qw(pp); while(<DATA>){ my @points = map{ s/\s+// } split("\t", $_); print "\n\@points =\n", pp \@points; #More code here } __DATA__ 0.000 12 0.232 13 11 text that c +an have space 1.000 13 0.534 14 12 More text t +hat would be ok 2.000 14 0.876 15 13 yet more te +xt
But I get this:
@points = [1] @points = [1] @points = [1]
Which definitely makes me think I have a context error going. What's the appropriate way to do this? (I know that the s/\s+// will remove the white space in the text too, I'm ok with that for now, I'd like to remove it from around the floats first.)
Effective use of map has always been my Everest, and with your help I will summit it this time!
Thanks in advance for your wisdom!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |