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
In reply to Re^2: problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
by Lotus1
in thread problem with splitting file on whitespace: how to circumvent inconsistent formatting through file
by angela2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |