#!/usr/bin/perl use strict; use warnings; use Getopt::Std; my %opt; Get_Args( \%opt ); for ( sort { $a <=> $b } keys %opt ) { if ( uc $opt{$_} eq 'F' ) { print "Channel $_ is set to Forever\n"; } elsif ( $opt{$_} =~ /^(\d\d?):(\d\d?)/ ) { my ($hr, $min) = ($1, $2); print "Channel $_ is set to $hr hour(s) and $min minute(s)\n"; } else { die "$opt{$_} is not a valid option for channel $_\n"; } } sub Get_Args { my $opt = shift; my $Usage = qq{Usage: $0 [options] -# -h : This help message. -# : Channel Number followed by duration F = forever HH:MM = Hours and Minutes } . "\n"; my $channels = join ':', 1..10; # Adjust for the max # of channels getopts( "h$channels:" , $opt ) or die $Usage; die $Usage if $opt->{h} || ! keys %$opt; }