/[cvs]/nfo/perl/libs/shortcuts.pm
ViewVC logotype

Contents of /nfo/perl/libs/shortcuts.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sat Feb 22 17:19:36 2003 UTC (21 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.3: +15 -1 lines
+ unix compatibility fix

1 ## ---------------------------------------------------------------------------
2 ## $Id: shortcuts.pm,v 1.3 2003/02/14 14:17:04 joko Exp $
3 ## ---------------------------------------------------------------------------
4 ## $Log: shortcuts.pm,v $
5 ## Revision 1.3 2003/02/14 14:17:04 joko
6 ## - shortened seperator
7 ##
8 ## Revision 1.2 2003/02/11 05:14:28 joko
9 ## + refactored code from libp.pm
10 ##
11 ## Revision 1.1 2003/02/09 04:49:45 joko
12 ## + shortcuts now refactored to this file
13 ##
14 ## ---------------------------------------------------------------------------
15
16
17 package shortcuts;
18
19 use strict;
20 use warnings;
21
22 require Exporter;
23 our @ISA = qw( Exporter );
24 our @EXPORT_OK = qw(
25 strftime
26 now today
27 run_cmd run_cmds
28 get_chomped
29 bool2status
30 );
31
32
33 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main
34
35 use Data::Dumper;
36 use POSIX qw(strftime);
37
38 # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
39 # see "perldoc -f localtime"
40
41 sub now {
42 my $options = shift;
43 my $pattern = "%Y-%m-%d %H:%M:%S";
44 $pattern = "%Y-%m-%d_%H-%M-%S" if $options->{fs};
45 my $result = strftime($pattern, localtime);
46 return $result;
47 }
48
49 sub today {
50 return strftime("%Y-%m-%d", localtime);
51 }
52
53 sub run_cmd {
54 my $cmd = shift;
55 my $caption = shift;
56 #$cmd = 'perl ' . $cmd;
57 my $sep = "-" x 60;
58 print $sep, "\n";
59 print " ", $cmd, "\n";
60 print " ", $caption, "\n" if $caption;
61 print $sep, "\n";
62
63 # fix for unix: prefix command with './' if no pathname (relative or absolute) included
64 if (!RUNNING_IN_HELL()) {
65 if ($cmd !~ m/\//) {
66 $cmd = "./$cmd";
67 }
68 }
69
70 system($cmd);
71 #`$cmd`;
72 print "ready.", "\n";
73 }
74
75 sub run_cmds {
76 foreach (@_) {
77 run_cmd($_);
78 }
79 }
80
81 sub get_chomped {
82 my $str = shift;
83 chomp($str);
84 return $str;
85 }
86
87 sub bool2status {
88 my $bool = shift;
89 return ($bool ? 'ok' : 'failed');
90 }
91
92 sub RUNNING_IN_HELL () { $^O eq 'MSWin32' }
93
94
95 1;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed