Have the following data in a text file:
Can anyone think of a more elegant solution to repeat the regex search below which basically repeats every x-x pair. The current code caters for fixed number of matches of 7, but it could be more.
Eventual format needs to be in the csv format, where each row above is re-aligned in following structure:
Code:
0 0-0 1-0 2-0 3-0 0-1 1-1 2-1
1 0-2 1-2 2-2 3-2 0-3 1-3 2-3
2 0-4 1-4 2-4 3-4 0-5 1-5 2-5
3 0-6 1-6 2-6 3-6 0-7 1-7 2-7
...
etc
Can anyone think of a more elegant solution to repeat the regex search below which basically repeats every x-x pair. The current code caters for fixed number of matches of 7, but it could be more.
Code:
open(FILE,"sample.txt") || die "Cannot open sample.txt $!\n";
while(@line = <FILE>) {
$line = FILE;
foreach my $line(@line){
if ($line =~ /\s+\d+\s+\d+-\d+\s+\d+-\d+\s+\d+-\d+\s+\d+-\d+\s+\d+-\d+\s+\d+-\d+\s+\d+-\d+/){
@records = split(/-/,$line);
#put into csv here;
}
}
}
Eventual format needs to be in the csv format, where each row above is re-aligned in following structure:
Code:
0,0,0
0,1,0
0,2,0
0,3,0
0,0,1
0,1,1
0,2,1
1,0,2
1,1,2
etc