Created
January 16, 2013 06:25
-
-
Save sati2013/4545085 to your computer and use it in GitHub Desktop.
Perl options test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Getopt::Long qw(GetOptions); | |
my %opts; | |
GetOptions(\%opts, | |
'fname=s', | |
'lname=s', | |
) or usage (); | |
if (not $opts{fname} or $opts{fname} !~ /^[a-zA-Z]+$/){ | |
print " $opts{fname} <--"; | |
usage("First name must be alphabetic"); | |
} | |
if (not $opts{lname} or $opts{lname} !~ /^[a-zA-Z]+$/){ | |
usage("Last name must be alphabetic"); | |
} | |
my $username = lc(substr($opts{lname}, 0,1) . $opts{fname}); | |
my $home = "/opt/$username"; | |
print "Username: $username\n"; | |
sub usage { | |
my ($msg) = @_; | |
if ($msg) { | |
print "$msg \n\n"; | |
} | |
print "Usage: $0 --fname FirstName --lname LastName\n"; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment