-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetopt_std.pl
More file actions
27 lines (25 loc) · 844 Bytes
/
Copy pathgetopt_std.pl
File metadata and controls
27 lines (25 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
our ($opt_h, $opt_f);
getopts('hf:');
if($opt_h)
{
print "----------------------------------------------------------------\n";
print "This program sorts a given file and removes any duplicate lines\n\n";
print "Usage:\n";
print "./getopt_std.pl -h \t\tDisplays this help\n";
print "./getopt_std.pl -f filename \tfile to be sorted uniquely\n";
print "----------------------------------------------------------------\n";
}
elsif($opt_f)
{
# no need file test if default behavior of command serves the purpose
my $cmd_exit_value = system("sort -u $opt_f -o $opt_f");
print "$opt_f is now uniquely sorted\n" unless($cmd_exit_value);
}
else
{
print "Oops! Something went wrong\nUse './getopt_std.pl -h' to get help\n";
}