#!/usr/bin/perl use strict; use warnings; # use 5.010; use List::Util qw( first ); use Tie::File; die "Usage: $0 report status\n" if 2 != @ARGV; my $report_file = shift @ARGV; my $status_file = shift @ARGV; # open report for reading open my $rfh, '<', $report_file or die "open($report_file,<) failed: $!"; # tie status file to array tie( my @status, 'Tie::File', $status_file ) or die "Cannot tie $status_file: $!"; LINE: while ( my $line = <$rfh> ) { warn "(D) read: $line\n"; # skip empty lines or with # at the start of a line next LINE if $line =~ m/^[\s]*$|^#/; chomp $line; # split into fields my ( $field1, $field2, $date1, $date2 ) = split m/\t/, $line; # no action if "date2" is not "-"; read next line next LINE if $date2 ne '-'; # prepare a string to compare from first three fields my $to_save = join "\t", $field1, $field2, $date1; # write to status file if string has not been seen yet # example : $foo = first { defined($_) } @list # first defined value in @list # $foo = first { $_ > $value } @list # first value in @list which # # is greater than $value if ( first { $_ eq $to_save } @status ) { pop @status, $to_save; } } close $rfh; __END__