Time of Update: 2017-02-27
Perl程式設計語言已經有26年的曆史了。1987年12月18日 Larry Wall 推出了 Perl 程式設計語言,而最早引用該語言的文章是在 88年的1月份,來自 Google 的 討論群組:Perl, a "replacement" for awk and sed. 該帖稱 Perl 用來替換 Linux 下的 awk 和 sed 工具 。Perl 的確讓 awk 和 sed 變得過時,Perl 使得系統管理員實現更強大的功能,而無需便攜複雜的 C 程式。Perl
Time of Update: 2017-01-18
本文和大家重點討論一下Perl文法中Perl變數的概念,Perl變數分為標量變數,陣列變數,聯絡關係陣列變數3類.Perl的變數對巨細寫敏感,好比:An,AN,an是3個分歧的變數,可是分歧範例的變數可以利用統一個名字。 Perl文法簡介 1.Perl變數 1.1.Perl文法中Perl變數分類
Time of Update: 2017-01-18
NULL值的判斷 $t{type1id} = $$pref{dbh}->selectrow_array("SELECT type1id FROM enq1 WHERE id = 3"); if ( $t{type1id} == 0 ) { print "Type1id is NULL\n"; } ==>不是數值項的話,這個語句有問題。數值項專用。 if ( length($t{type1id}) == 0 ) { print "Type1id is NULL\n"; } ==>
Time of Update: 2017-01-18
一、列表 列表是包含在括弧裡的一序列的值,可以為任何數值,也可為空白,如:(1, 5.3 , "hello" , 2),空列表:()。 註:只含有一個數值的列表(如:(43.2) )與該數值本身(即:43.2 )是不同的,但它們可以互相轉化或賦值。 列表例:
Time of Update: 2017-01-18
一、算術操作符 :+(加)、-(減)、*(乘)、/(除)、**(乘冪)、%(取餘)、-(單目負) (1)乘冪的基數不能為負,如 (-5) ** 2.5 # error; (2)乘冪結果不能超出電腦表示的限制,如10 ** 999999 # error (3)取餘的運算元如不是整數,四捨五入成整數後運算;運算子右側不能為零 (4)單目負可用於變數: - $y ; # 等效於 $y * -1二、整數比較操作符
Time of Update: 2017-01-18
程式調用遠端服務,為了確保可用性最好在使用前進行健康檢測,將異常的服務排除。複製代碼 代碼如下:#!/usr/bin/perl#use strict;use IO::Socket;my @servers;$servers[0]=['180.153.100.93',2222];$servers[1]=['180.153.100.93',22];$servers[2]=['180.153.100.93',80];my $i=0;my $interval=3;my
Time of Update: 2017-01-18
複製代碼 代碼如下:#!/usr/bin/perlopen( READ, "<$file" );readline READ; # skip the first linewhile (<READ>) {my ( $id, $axis1, $axis2, $axis3, $value ) = split / /;$line = sprintf ( "%d %d %d %d %d %d",$id, $axis1, $axis2, $axis3, $value, $axis1 +
Time of Update: 2017-01-18
用Open() 函數開啟檔案開啟檔案的常用方法是:複製代碼 代碼如下:open(FH, "< $filename")or die "Couldn't open $filename for reading: $!";open()
Time of Update: 2017-01-18
1. 一次性將檔案中的所有內容讀入一個數組中(該方法適合小檔案): 複製代碼 代碼如下:open(FILE,"filename")||die"can not open the file: $!";@filelist=<FILE>;foreach $eachline (@filelist) { chomp $eachline;}close FILE;@filelist=<FILE>
Time of Update: 2018-07-26
問題:我現在想把 awk '{print $2}' from_file > to_file 這句話加入perl程式中,但是加上sytem和``之後都無法執行 答案:有很多命令在命令列可以執行的,但是不能直接放入perl中執行,需要對特殊字元進行轉義。$ 前面都加上\試試,不然$3會被當作是perl中的變數。 建議最好是用perl直接寫比較好,實在不會寫,你把awk '{print $2}' from_file >
Time of Update: 2018-07-28
在 PERL 開發中,通常可以用 system 函數或 `` 操作符來執行系統命令,但注意對 alias, bg, bind, break, builtin, cd, command, compgen, complete, continue, declare, dirs, disown, echo,
Time of Update: 2018-12-04
1、從 www.cpan.org 搜尋你所需要的模組,下載下來,一般是gz,或者tgz格式2、用winRAR之類解壓縮軟體接壓縮3、進入COMMAN模式,進入到剛才解壓縮的檔案夾下,含有“Makefile.PL”檔案的目錄下:依次運行: perl Makefile.PL nmake nmake test nmake install安裝就完成了.我的系統是Windows XP, 安裝的是ActivePerl-5.8.8.817-MSWin3
Time of Update: 2018-12-03
/* 尋找字串是Regex的主要應用。在php中,可以作用的並且用於匹配perl風格Regex的 主要函數是 preg_match()。該函數原型如下 int preg_match(string pattern, string subject[,array matches[,int flags]]) 在subject中搜尋pattern。$matches[0]將包含與整個模式比對的文本,
Time of Update: 2018-12-03
In item 116 of the book "Effective Perl", author demonstrates how to use unpack to process fix-width columnar data. I tried to write a toy code for practice, and found two things need to note.First thing, MUST use single quote ' before and
Time of Update: 2018-12-05
第一個perl指令碼是同事幫忙寫的。這個功能用JAVA實現後,中途不拋異常退出;用perl後,正常。同事幫忙寫,我自己修改調試通過,竟然對perl有了一定的瞭解。寫下來,備忘,說不定今天是個新的開始。#!/usr/bin/perluse DBI;#串連資料庫,就是這麼方便$dbh = DBI->connect("DBI:mysql:newWap:172.16.58.36", "root","");#perl ioopen (F, "data.txt");open (OUT,
Time of Update: 2018-12-05
一、簡單變數===========1. 整型$x = 123456;PERL中將整型資料存放在浮點寄存器中,實際上整型變數在PERL中是當作浮點數來看但,只不過是一種浮點數據的特列。8進位資料以0打頭$var1 = 047(十進位39)16進位資料以0x打頭$var2 = 0x1f(十進位31)2. 浮點型浮點寄存器通常是不能精確的儲存浮點數,會產生誤差。使用浮點數時需要注意指數範圍通常是-309到+308。e.g.11.4, -0.3, .3, 3., 64.1e+02,
Time of Update: 2018-12-04
######################### 1001 ############################## use 5.010;while(<>){ my @num = split; say $num[0] + $num[1];}######################### 1048 ##############################my $n = 12;my $sum = 0;while ( $n -- ){ chomp(my
Time of Update: 2018-12-07
1: 子串截取 $value = substr($string, $offset, $count);$value = substr($string, $offset); substr($string, $offset, $count) = $newstring;substr($string, $offset, $count, $newstring); # 與上一條語句等價substr($string, $offset) =
Time of Update: 2018-12-07
最近因為項目需要,需要在多個古老的linux/unix版本上完成一個工具,有些沒有python所在,不得不重拾perl文檔……再讀perl文檔的,是一個讓人吐血的過程。習慣了python> 2.4 的文法和core庫組織,那種相對來說比較合理的安排和統一的格式,perl的就顯得非常的不合理。我想這應該是因為它所出現的那個石器時代造成了這些個時代斷層,最初的優雅和驚豔經過前僕後繼維護者的縫縫補補,變成了現在這個百變妖精的德行……1,perl的關鍵字文法多變和詭異,比如 unless 迴圈;2
Time of Update: 2018-12-07
1 基本文法參考http://ind.ntou.edu.tw/~dada/cgi/Perlsynx.htm 2 設定檔http://www.itqun.net/content-detail/93521.htmlhttp://www.9php.com/FAQ/cxsjl/perl/2009/07/4285989147407.htmlhttp://blog.chinaunix.net/u/29291/showart_344126.html【test.pl】Code highlighting