Perl的一些重要模組使用介紹
1) use Cwd;
my $directory = cwd;
2) use Fatal qw/ open chdir/;
chdir '/home/merlyn'; # "or die" is now supplied automatically
3) use File::Basename;
for (@ARGV){
my $basename = basename $_;
my $dirname = dirname $_;
print "That's file $basename in directory $dirname.\n";
}
4)use File::Copy;
copy("source", "destination")
or die "Can't copy 'source' to 'destination' : $!";
5) use File::Spec;
my $current_directory = File::Spec->curdir;
or die "Can't open current directory '$current_directory': $!";
6)use Image::Size;
#Get the size of fred.png
my($fred_height, $fred_width) = imgsize("fred.png");
die "Couldn't get the size of the image"
unless defined $fred_height;
7) use Net::SMTP;
my $from = 'YOUR_ADDRESS_GOES_HERE'; #maybe fred@bedrock.edu
my $site ='YOUR_SITE_NAME_GOES_HERE'; #maybe bedrock.edu
my $smtp_host = 'YOUR_SMTP_HOST_GOES_HERE'; #maybe mail or mailhost
my $to = 'president@whitehouse.gov';
my $smtp = Net::SMTP->new($smtp_host, Hello => $site);
$smtp->mail($from);
$smtp->to($to);
$smtp0>data();
$smtp->datasend("To: $to\n");
$smtp->datasend("Subject: A message from my Perl program.\n");
$smtp->datasend("\n");
$smtp->datasend("This is just to let you know,\n");
$smtp->datasend("I don't care what those other people say about you,\n");
$smtp->datasend("I still think you're doing a great job.\n");
$smtp->datasend("\n");
$smtp->datasend("Have you considered enacting a law naming Perl \n");
$smtp->datasend("the national programming language?\n");
$smtp->dataend(); #Not datasend!
$smtp->quit;
8)use POSIX;
print "Please enter a number:";
chomp(my $str = );
$! = 0; #Clear out the error indicator
my($num, $leftover) = POSIX::strtod($str);
if($str eq ''){
print "That string was empty!\n";
}elsif($leftover){
my $remainder =substr $str, -$leftover;
print "The string '$remainder' was left after the number $num.\n";
}elsif($!){
print "The conversion function complained: $!\n";
}else{
print "The seemingly-valid number was $num.\n";
}
9)use Sys::Hostname;
my $host = hostname;
print "This machine is known as '$host'.\n";
10)use Text::Wrap;
my $message = "This is some example text which may be longer ". "than the width of your output device, so it needs to ".
"be wrapped to fit properly as a paragraph. ";
print wrap("\t", "", "$message\n");
11)use Time::Local;
my $time = timelocal($sec, $min, $hr, $day, $mon, $year);
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24104518/viewspace-722192/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Django重要元件之Auth模組介紹Django元件
- 一些重要 Docker 命令的簡單介紹Docker
- Tengine 常用模組使用介紹
- 使用CPAN安裝Perl模組
- perl Statistics::Descriptive Perl 的統計模組
- RecyclerView 介紹 02 – 重要概念View
- mod_perl 程式設計介紹 (轉)程式設計
- Perl的包和模組
- Python模組介紹Python
- TSM功能模組介紹
- node表格模組exceljs介紹1–基本使用ExcelJS
- 【StoneDB 模組介紹】伺服器模組伺服器
- 網頁抓取的重要性介紹網頁
- ModStartCMS模組開發介紹
- 3.03 模組外掛介紹
- nodejs主要模組介紹NodeJS
- 人工智慧重要會議介紹人工智慧
- Python的常見模組:OS和 time模組介紹Python
- mysql一些引數的介紹MySql
- mysql 字首索引 的一些介紹MySql索引
- python3中的re模組簡單介紹及使用Python
- Istio所有模組、Service、Pod的功能介紹
- Nginx通過內建的Perl模組執行Perl程式Nginx
- perl的包(package)和模組(PM)Package
- Perl5的包和模組
- 比較perl模組的版本(轉)
- Android模組化框架介紹Android框架
- nodejs常用核心模組介紹NodeJS
- Perl 模組 Hash::Merge
- Perl模組之Tie::File
- perl cpan 模組安裝
- 如何使用 rsync 備份 Linux 系統的一些介紹Linux
- Google Analytics 的一些用法介紹Go
- 介紹一些有趣的MySQL pager命令MySql
- Python的包(package)和模組(module)介紹PythonPackage
- HanLP分類模組的分詞器介紹HanLP分詞
- Nginx 架構——【核心流程+模組介紹】Nginx架構
- 簡單介紹python process模組Python