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 #!/usr/bin/perl
use strict; use warnings; 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 = (); my %seen = ();
for (;;) { my $in_file;
my $input = <STDIN>;
last if not defined $input; if ($file) {
chomp $input; open my $in_file, $file or die "Could not open $file: $!";
my @l = $input =~ /([0-9]+\/[0-9]+\/[0-9]+)/mg; while (my $line = <$in_file>) {
foreach my $item (@l) { last if not defined $line;
$seen{$item}++; 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; my @uniq = sort gw_comp keys %seen;
if (@uniq) { if (@uniq) {
print "@uniq\n"; if ($newlines) {
foreach my $item (@uniq) {
print "$item\n";
}
} else {
print "@uniq\n";
}
} }
sub gw_comp{ sub gw_comp{