#!/usr/bin/perl -w use warnings; use strict; use cwd; our $input=""; our $web=""; our $help=""; our $version=""; our $path=""; foreach my $input(@ARGV){ if($input =~ m/\-d(.*)/) { $path=$1; } elsif($input =~ m/\-f(.*)/) { if($1 eq "h") { $web = "h"; } elsif($1 eq "t") { $web = "t"; } } elsif($input =~ m/\-h/ ){ $help = "h"; } elsif($input =~ m/\-s(.*)/) { if($1 eq "a") { $web = "a"; } elsif($1 eq "d") { $web = "d"; } } elsif($input =~ m/\-v/ ){ $version = "v"; } } #calling of methods if($web eq "h") { gethtml(); } if($web eq "t") { gettext(); } if($help eq "h") { gethelp(); } if($version eq "v") { getversion(); } if($web eq "a") { sortedasc(); } if($web eq "d") { sorteddesc(); } #methods sub gethtml{ open(FH, ">plain.html"); print "sasasasas"; close (FH); } sub gettext{ open(FH1, "/home/GUAN/Data/output.txt") or die "Error, no such file found"; print ; close (FH1); } sub getdefault{ open(FH1, "/home/GUAN/Data/output.txt") or die "Error, no such file found"; print ; close (FH1); } sub sorteddesc{ open(FH1, "/home/GUAN/Data/output.txt") or die "Error, no such file found"; print sort{ $b cmp $a } ; close (FH1); } sub sortedasc{ open(FH1, "/home/GUAN/Data/output.txt") or die "Error, no such file found"; print sort{ $a cmp $b } ; close (FH1); } sub gethelp { print "Usage: {file name} [switches] ‐dpath directory to search for html files (default: .) ‐f[th] output in text or html mode (default: text) ‐h print this message and exit ‐s[adn] sort in ascending, descending or none (default: none) ‐v print version and exit"; } sub getversion { print "***********************************************************************\n ST2614 Assignment 1, Ver. 5.0 done by Guan Zhimin p1333114 class 2A/01\n ***********************************************************************"; } # sub lookfor { # my $dir = '.'; # opendir(DIR, $dir) or die $!; # while (my $file = readdir(DIR)) { # next if ($file =~ m/^\./); # print "$file\n"; # } # closedir(DIR); # exit 0; # }