码迷,mamicode.com
首页 > 其他好文 > 详细

perl格式化模板

时间:2014-11-29 11:57:36      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   sp   for   on   2014   log   bs   

#!/usr/bin/env perl
use warnings;
use strict;
use Getopt::Long;
use FindBin qw($Bin);
use File::Basename qw(basename);
use File::Spec::Functions qw(rel2abs);

##### main program #####
my $mainPL = basename($0);
my $ysbin = "$Bin/ysbin";

&main;
exit;

sub main
{
	&usage if(@ARGV < 1);

	my $command = shift(@ARGV);
	my %func = 
	(
		"venn"  => \&venn,
	);

	if(!defined($func{$command}))
	{
		warn("\n\tUnknown command: \"$command\"\n");
		&usage;
	}
	&{$func{$command}};
}

sub usage
{
	die(qq/
	Usage:	$mainPL <command> [options]
	Command:
		venn           draw venn pics and get venn matrix of samples.
	\n/);
}

##### sub program #####
sub venn
{
	my $pl = "perl $ysbin/venn.pl";
	my $help;
	GetOptions(
		"help|h" => \$help,
	);
	die `$pl 2>&1` if($help);

	die(qq/
	Usage:	$mainPL venn <files> <labels>
	Notes:
		1. Need R and VennDiagram package of R
		2. <files> means a,b,...(2~5 files); <labels> means x,y,...(2~5 labels)
	Options:
		-help|-h			see the detail help information about venn
	\n/) if(@ARGV != 2);

	&runSH("$pl -f $ARGV[0] -l $ARGV[1]");
}

sub runSH
{
	my ($sh) = @_;
	&showTime($sh);
	`$sh`;
	&showTime("Task is completed~");
}

sub showTime
{
	my ($text) = @_;
	my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
	my $format_time = sprintf("[%d-%.2d-%.2d %.2d:%.2d:%.2d]", $year+1900, $mon+1, $mday, $hour, $min, $sec);
	print STDERR "$format_time $text\n";
}

perl格式化模板

标签:blog   io   ar   sp   for   on   2014   log   bs   

原文地址:http://blog.csdn.net/skenoy/article/details/41593873

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!