add simple command line opts

master
Vincent Schweiger 2024-01-28 15:34:35 +01:00
parent 9e2e13f32c
commit 9a95a8add6
Signed by: vincent
GPG Key ID: F83B0F0E383CC23F
1 changed files with 36 additions and 8 deletions

View File

@ -1,22 +1,50 @@
#!/usr/bin/perl
use strict; use warnings;
use Getopt::Long;
my $newlines = '';
my $file = '';
GetOptions ("newlines" => \$newlines, # print newlines
"file=s" => \$file # input file
) or die("Error in command line arguments\n");
my %seen = ();
for (;;) {
my $input = <STDIN>;
last if not defined $input;
chomp $input;
my @l = $input =~ /([0-9]+\/[0-9]+\/[0-9]+)/mg;
foreach my $item (@l) {
$seen{$item}++;
my $in_file;
if ($file) {
open my $in_file, $file or die "Could not open $file: $!";
while (my $line = <$in_file>) {
last if not defined $line;
chomp $line;
my @l = $line =~ /([0-9]+\/[0-9]+\/[0-9]+)/mg;
foreach my $item (@l) {
$seen{$item}++;
}
}
close $in_file;
} else {
for (;;) {
my $input = <STDIN>;
last if not defined $input;
chomp $input;
my @l = $input =~ /([0-9]+\/[0-9]+\/[0-9]+)/mg;
foreach my $item (@l) {
$seen{$item}++;
}
}
}
my @uniq = sort gw_comp keys %seen;
if (@uniq) {
print "@uniq\n";
if ($newlines) {
foreach my $item (@uniq) {
print "$item\n";
}
} else {
print "@uniq\n";
}
}
sub gw_comp{