D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
usr
/
share
/
doc
/
perl-Getopt-Long
/
examples
/
Filename :
parsetime.pl
back
Copy
#!/usr/bin/perl # This is a (working) example of how to write a helper routine for # Getopt::Long to deal with specific cases. # # The basic principle is: # - specify the option type to be string # - specify a code reference to handle the parsing an assignment. # # This example parses time specifications in the form HH:MM:SS.mmm, where # unneeded parts may be left out. use strict; use warnings; use Getopt::Long; # The helper routine. It will be called to handle the actual delivery # of the option value. # There are two parameters: the option name, and the value to be # assigned. # Note the use of 'die' to signal errors back to Getopt::Long. sub parsetime { my ($opt_name, $opt_value) = @_; my $val = 0; unless ( $opt_value =~ / ^ # beginning of value string (?:(\d+):)? # hours (?:(\d+):)? # minutes (\d+(?:\.\d+)?) # seconds + fraction $ # end of value string /x ) { die("Value \"$opt_value\" invalid for option $opt_name\n"); } # Return the value. ( defined $1 ? 3600*$1 : 0) + ( defined $2 ? 60*$2 : 0) + $3; } @ARGV = ("-time", "1:24.14") unless @ARGV; my $time; GetOptions("time=s" => sub { $time = &parsetime }) && print "time = $time seconds\n";
Name
Size
Last Modified
Owner
Permissions
Actions
README
0.314
KB
July 23 2006 2:34:06
root
0644
parsetime.pl
1.189
KB
October 08 2004 11:40:22
root
0644
skel1.pl
1.971
KB
April 19 2011 7:07:03
root
0644
skel2.pl
2.556
KB
June 02 2015 8:40:04
root
0644
skel3.pl
2.523
KB
July 09 2010 12:30:13
root
0644
skel4.pl
2.755
KB
July 04 2013 12:43:40
root
0644
2017 © D7net | D704T team