PERL

PERL 옵션 설정

고요한하늘... 2012. 11. 7. 13:44

HELP 옵션과 VERBOSE 설정을 예로



my $options = {}; # `my' defines a local variable.
getopts("hv", $options);
$debug_mode = $options->{v};
 
sub print_usage_and_exit {
  my $fh = shift || *STDOUT;
  my $message = shift;
 
  print $fh $message, "\n" if defined $message;
  print $fh <<END;
Usage: $0 [-h] [-v] [-v] <keywords_file> [<output_file>]
 keywords_file             - input filename which lists keywords
 output_file               - output filename to write
 
 Options -
  -h          shows this help message
  -v          enables verbose mode
END
  exit;
}
 
print_usage_and_exit if $options->{h};