Here's my guess at something like what you want. Instead of printing @match and @nomatch at the end, just write their contents to the proper files, and change the input to read from your input file.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11109150 use warnings; my $x = 9; my %uniques; my @match; my @nomatch; while( <DATA> ) { print; for my $element ( split ) { if( keys %uniques < $x ) { $uniques{ $element }++; } else { if( $uniques{ $element } ) { push @match, $element; } else { push @nomatch, $element; } } } } print "\nMATCH:\n@match\n\nNOMATCH:\n@nomatch\n"; __DATA__ 1 2 6 4 5 6 7 8 9 10 1 2 11 12 13 6 14 15 16 17
Outputs:
1 2 6 4 5 6 7 8 9 10 1 2 11 12 13 6 14 15 16 17 MATCH: 1 2 6 NOMATCH: 11 12 13 14 15 16 17
In reply to Re^3: Reversing the action of the while loop
by tybalt89
in thread Reversing the action of the while loop
by Scotmonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |