perl格式化模板

#!/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";
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值