in reply to Re: problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
in thread problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
Hi GotToBTru, \d does not match commas so your program splits up the numbers. If you add the comma in a character class it works.
use warnings; use strict; while(<DATA>) { chomp (my $line = $_); my @columns = $line =~ m/\s*(-?\d+)/g; print "@columns\n"; } __DATA__ 15,567 -25,324-45,234 15,567-25,324-45,234 -13,345 53,562 13,452 -7,521-22,454-54,671
Output: 15 567 -25 324 -45 234 15 567 -25 324 -45 234 -13 345 53 562 13 452 -7 521 -22 454 -54 671
Here it is with the comma added.
use warnings; use strict; while(my $line = <DATA>) { my @columns = $line =~ m/\s*(-?[,\d]+)/g; print "@columns\n"; } __DATA__ 15,567 -25,324-45,234 15,567-25,324-45,234 -13,345 53,562 13,452 -7,521-22,454-54,671
Output: 15,567 -25,324 -45,234 15,567 -25,324 -45,234 -13,345 53,562 13,452 -7,521 -22,454 -54,671
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
by angela2 (Sexton) on Jul 05, 2016 at 09:24 UTC |