Perl常用Lib

1. POSIX

use POSIX qw(strftime);

use constant NOW => strftime( '%Y%m%d.%H%M%S', localtime );

use constant TODAY => strftime( '%Y%m%d', localtime );

2. Data::Dumper

use Data::Dumper;

Dumper ( \%hash);

Dumper(\@array);

Data::Dumper->Dump( [\%hash], ["HASHDATA"] );

Data::Dumper->Dump( [\@array],["ARRAYDATA"]);

3. Getopt::EvaP

use GetOpt::Evap;

use constant ME => File::Basename::basename($0);

##############################
#Set up the options processing
#
my %opt = (); 
my (@PDT) = split (/\n/, <<"//end-of-PDT");
PDT @{[ME]}
    server,            S: string 
    db_user,         U: string = "dev"
    db_pass,        P: string = "developer"
    db_set,           D: string = "mydatabase"
    ops,                ops: string
    log_dir,           ld: file = "/tmp/test_dir/LOG"
    todo_dir,         td: file = "/tmp/test_dir/TODO"
    done_dir,       dd: file = "/tmp/test_dir/DONE"
    email,            e: string
    PDTEND optional_file_list
//end-of-PDT
;

my (@MM) = split (/\n/, <<"//end-of-MM");

@{[ME]}:  Some comments here.
    .server
    Server to connect to and apply the SQL.
    .db_user
    User name to login as.
    .db_pass
    Password for user.
    .db_set
    Destination database.

    . Name of original data file from which this SQL was generated. Name
    to be used in the mail message.
    .log_dir
    Directory where to place the generated logs.
    .todo_dir
    Directory where to take the todo sql file
    .done_dir 
    Directory where to place the processed sql file
    .email
    Email where the results will be sent.
//end-of-MM
;
EvaP(\@PDT, \@MM, \%opt)
    or die("Cannot parse arguments: \"@ARGV\" using Getopt::EvaP!");

print Dumper %opt;

4. File::Basename

use File::Basename;

use constant SCRIPT_NM => basename($0);

my $PROG = basename($0)    || die "Could not determine program name  using 'basename':$?";

my $CURRDIR =dirname($0);

my $filename = "/tmp/test_dir/test.txt";

my $dir = dirname($filename);# /tmp/test_dir

my $file = basename($filename);#test.txt

my ($base, $dir, $suffix) = fileparse($filename,'.txt');

5. File::Copy

use File::Copy;

my $src_file = "/tmp/test_dir/src.xls";

my $dst_file = "/tmp/test_dir/dst.xls";

die( "Unable to move '$src_file' to '$dst_file'.") 

unless move( $src_file, $dst_file );


useFile::Copy;

copy("file1","file2")or die "Copyfailed: $!";

copy("Copy.pm",\*STDOUT);

move("/dev1/fileA","/dev2/fileB");

 

useFile::Copy"cp";

$n = FileHandle->new("/a/file","r");

cp( $n, "x")


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值