Skip to content

Instantly share code, notes, and snippets.

@sati2013
Created January 16, 2013 06:25
Show Gist options
  • Save sati2013/4545085 to your computer and use it in GitHub Desktop.
Save sati2013/4545085 to your computer and use it in GitHub Desktop.
Perl options test
#!/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