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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sat Feb 22 17:26:13 2003 UTC (21 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.4: +11 -3 lines
+ enhanced unix compatibility fix

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

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