1 |
joko |
1.1 |
## --------------------------------------------------------------------------- |
2 |
|
|
## $Id: shortcuts.pm,v 1.3 2003/01/22 17:58:48 root Exp $ |
3 |
|
|
## --------------------------------------------------------------------------- |
4 |
|
|
## $Log: shortcuts.pm,v $ |
5 |
|
|
## --------------------------------------------------------------------------- |
6 |
|
|
|
7 |
|
|
|
8 |
|
|
package shortcuts; |
9 |
|
|
|
10 |
|
|
use strict; |
11 |
|
|
use warnings; |
12 |
|
|
|
13 |
|
|
require Exporter; |
14 |
|
|
our @ISA = qw( Exporter ); |
15 |
|
|
our @EXPORT_OK = qw( |
16 |
|
|
strftime |
17 |
|
|
now today |
18 |
|
|
run_cmd run_cmds |
19 |
|
|
get_chomped |
20 |
|
|
); |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
24 |
|
|
|
25 |
|
|
use Data::Dumper; |
26 |
|
|
use POSIX qw(strftime); |
27 |
|
|
|
28 |
|
|
# $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; |
29 |
|
|
# see "perldoc -f localtime" |
30 |
|
|
|
31 |
|
|
sub now { |
32 |
|
|
my $options = shift; |
33 |
|
|
my $pattern = "%Y-%m-%d %H:%M:%S"; |
34 |
|
|
$pattern = "%Y-%m-%d_%H-%M-%S" if $options->{fs}; |
35 |
|
|
my $result = strftime($pattern, localtime); |
36 |
|
|
return $result; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
sub today { |
40 |
|
|
return strftime("%Y-%m-%d", localtime); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
sub run_cmd { |
44 |
|
|
my $cmd = shift; |
45 |
|
|
my $caption = shift; |
46 |
|
|
#$cmd = 'perl ' . $cmd; |
47 |
|
|
my $sep = "-" x 90; |
48 |
|
|
print $sep, "\n"; |
49 |
|
|
print " ", $cmd, "\n"; |
50 |
|
|
print " ", $caption, "\n" if $caption; |
51 |
|
|
print $sep, "\n"; |
52 |
|
|
system($cmd); |
53 |
|
|
#`$cmd`; |
54 |
|
|
print "ready.", "\n"; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
sub run_cmds { |
58 |
|
|
foreach (@_) { |
59 |
|
|
run_cmd($_); |
60 |
|
|
} |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
sub get_chomped { |
64 |
|
|
my $str = shift; |
65 |
|
|
chomp($str); |
66 |
|
|
return $str; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
1; |