Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use autodie qw(open close);
- # Replace data.txt with your file name.
- my $file = 'data.txt';
- open my $FH, '<', $file;
- my $index = 0;
- my @data; # Array to store data
- my @indices; # Array to store indices
- while (my $row = <$FH>) {
- chomp $row;
- if ($row =~ /(\d+\s*:\s*\d+\s*:\s*\d+\.\d+)\.(\d+)/) {
- # Put data into the two arrays
- push @data, $row;
- push @indices, [$2, $index];
- }
- $index++;
- }
- close $FH;
- # Sort indices by id
- my @indices_sorted = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @indices;
- while (@indices_sorted) {
- # Here we assume the data are always paired.
- # You may need to deal with the issue.
- my $i = shift @indices_sorted;
- my $j = shift @indices_sorted;
- # You may use the two indices to access @data
- # and do more.
- print $i, ", ", $j, "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement