开发者

Use perl script to fill in values in data set

开发者 https://www.devze.com 2023-01-30 09:59 出处:网络
I have a series of numbers (in a text file) from 90,000 to 1,000,000 that correspond to files that I am missing. I would like to take this set and mark these files as \"1\" as a second column next to

I have a series of numbers (in a text file) from 90,000 to 1,000,000 that correspond to files that I am missing. I would like to take this set and mark these files as "1" as a second column next to a complete series of numbers 90,000 to 1,000,000. Fo开发者_运维百科r example for series 1to13 (which would correspond to the "missing" files):

3
7
10
12

I would like to create a data set:

1    0
2    0
3    1
4    0
5    0
6    0
7    1
8    0
9    0
10   1
11   0
12   1
13   0

I would like to be able to execute this in perl.


Assuming they are sorted:

use strict;
use warnings;

my $last = 89999;
while (my $next = <>) {
    chomp($next);
    print $last, " 0\n" while ++$last < $next;
    print "$next 1\n";
}
print $last, " 0\n" while ++$last <= 1000000;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号