$a =~ tr/[A-Z]/[a-z]/;
Try it with
perl -e '$a = "ABCD"; $a =~ tr/[A-Z]/[a-z]/; print $n;'$a;
$a =~ tr/[A-Z]/[a-z]/;
perl -e '$a = "ABCD"; $a =~ tr/[A-Z]/[a-z]/; print $n;'$a;
#!/usr/bin/env perl
my @a = ("sh -c 'asdfsadf ls'", "echo hi", "echo a");
foreach my $b (@a)
{
if(fork()==0)
{
exec($b);
die "Gahh: $b";
}
}
print "done\n";
perl -e "exec('sh -c asdflkj'); die 'gahh';"
sub rec_print
{
my ($message, $lead) = @_;
if (ref($message) eq 'ARRAY')
{
# print ":\n";
rec_print($_, $lead . " ") foreach (@$message);
}
elsif (ref($message) eq 'HASH')
{
foreach my $k (keys %$message)
{
print "$lead$k:\n";
rec_print($message->{$k}, $lead . " ");
}
}
else
{
print "$lead$message\n";
}
}
#example
rec_print({a=>"abc", b=>"bcd"},"");
./datetime.pl ./datetime.pl "7:00" ./datetime.pl "+ 1 day + 1 hours" ./datetime.pl "-10 seconds"
#!/usr/bin/env perl
use strict;
use Date::Manip;
sub string2date
{
my ($str) = @_;
return int(UnixDate($str, "%s"));
}
sub date2string
{
my ($time) = @_;
return UnixDate("epoch $time", "%m/%d/%y %H:%M:%S");
}
sub date2timezone
{
my ($time, $tz) = @_;
return UnixDate(Date_ConvTZ(ParseDate("epoch $time"), '', $tz), '%m/%d/%y %H:%M:%S');
}
sub date2midnightSec
{
my ($time) = @_;
my @a = localtime($time);
return 3600*@a[2] + 60*@a[1] + @a[0];
}
my $intime = $ARGV[0];
$intime = 'now' unless defined $intime;
my $rawInTime = string2date($intime);
print "NYT: " . date2string($rawInTime) . "\n";
print "JST: " . date2timezone($rawInTime, "JST") . "\n";
print "Midnight Seconds: " . date2midnightSec($rawInTime) . "\n";
#!/usr/bin/env perl
use strict;
use Date::Manip;
#For the valid formats look at
#http://search.cpan.org/~muir/Time-modules-2003.0211/lib/Time/ParseDate.pm
my $period = 10;
my @tasks = (
{ time => "09:00:00", label => "morning", cmd => "echo 'good morning'"},
{ time => "01:34:00", label => "Hi", cmd => "echo 'good morning'"},
{ step => "+ 1 minutes", label => "5 mins", cmd => "echo '5 mins'"},
{ step => "+ 10 seconds", label => "10 seconsd", cmd => "echo '5 mins'"}
);
sub string2date
{
my ($str) = @_;
return int(UnixDate($str, "%s"));
}
sub secsDiff
{
my ($str) = @_;
return string2date($str) - string2date("now");
}
sub update_firetime
{
my ($task, $now) = @_;
my $new = $now;
if(defined $task->{time})
{
$new = string2date($task->{time});
$new += secsDiff("+ 1 day") if $new < $now;
}
elsif(defined $task->{step})
{
$new = $now;
$new += secsDiff($task->{step}) while $new <= $now;
}
$task->{fire_time} = $new;
}
sub boot
{
my $now = string2date("now");
update_firetime($_, $now)
foreach (@tasks);
}
sub execute
{
my ($task) = @_;
my $pid = fork();
if((defined $pid) && ($pid == 0))
{
if(defined $task->{xterm} && $task->{xterm} == 1)
{
#boot and leave an xt
my $label = $task->{label};
my $cmd = $task->{cmd};
my $sys_cmd = "xterm -xrm 'XTerm*foreground: red3' -xrm 'XTerm*background: black' -title 'CRONTAB:$label' -e sh -c \"$cmd; ksh\" &";
system($sys_cmd);
}
else
{
#just execute it..
system($task->{cmd});
}
exit(0);
}
}
sub cron_core
{
while(1)
{
my $now = string2date("now");
foreach my $task (@tasks)
{
if($now > $task->{fire_time})
{
print "fire! $task->{label}\n";
execute($task);
update_firetime($task, $now)
}
}
#cron loop an launch
print("sleeping.....\n");
sleep($period);
}
}
print "Operating with an accuracy of +/-$period seconds\n";
boot();
cron_core();
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd;
my $start=$ARGV[0];
sub find
{
my ($dirname) = @_;
my $dh;
opendir($dh, $dirname) or die "Couldn't open dir '$dirname': $!";
my @files = readdir($dh);
closedir($dh);
#print files...
foreach my $file (@files)
{
if(
($file) &&
($file !~ /^\.$/) &&
($file !~ /^\.\.$/)
)
{
my $path = "$dirname/$file";
print "$path\n";
if(-d "$path")
{
find("$path");
}
}
}
}
$start = "." unless $start;
find($start);