Time of Update: 2018-12-03
open(FILE,”這個檔案的路徑”);@content=<FILE>;$lineCount=@content; for($item=0;$item<$lineCount;$item++){$tileContent=$content[$item];$item++;If(tileContent =~^/~)#找到開頭是以 ~ 的行{$ComponentContent=$content[$item];$item++;If($ComponentContent
Time of Update: 2018-12-03
Perl中讀寫Excel很方便,貼段代碼為以後參考。讀寫Excel的組件需要另外安裝,指令如下: perl -MCPAN -e shell -> install Spreadsheet::WriteExcel perl -MCPAN -e shell -> install Spreadsheet::ParseExcel #!/usr/bin/perluse Spreadsheet::WriteExcel; #寫入Excel資料use
Time of Update: 2018-12-03
一、雜湊變數雜湊變數又稱關聯陣列;與普通的數組一樣,也可以使用下標來訪問其中的資料元素;不同的是,雜湊變數的下標不僅僅可以是非負整數,而且也可以是其它類型的簡單變數或變數值,也就是說,雜湊變數的下標索引可以是任意類型的簡單變數或變數值,稱為關鍵字;雜湊變數以字元“%”開頭;每個關鍵字都與一個值對應;雜湊變數的建立有兩種方式:使用數組的建立方式和通過關聯運算子“=>”的方式;%Hash = (Key1,Value1,Key2,Value2,Key3,Value3,Key4,Value4,
Time of Update: 2018-12-03
在編寫程式的過程中,常常要用到嵌套的迴圈結構,有時侯需要使用一種手段來中斷它;Perl提供了以下四個迴圈修飾符:continue、next、last、redo;1、continue語句塊:for迴圈的遞增列表是在迴圈體之後執行的,continue語句塊在功能上等價於迴圈的遞增列表;在while迴圈、until迴圈和foreach迴圈中可以加入continue語句塊:◆ while迴圈 while(條件運算式) { #while迴圈體 } continue
Time of Update: 2018-12-03
範圍(Scope)就是變數的有效範圍、可見範圍,變數只有在範圍中才會有效;Perl中,資料的範圍分為全域範圍、詞法範圍和動態範圍;Pe rl5中,可以使用關鍵字my和local來聲明變數以及限定變數的範圍;1、詞法域:Lexical使用my關鍵字聲明的變數稱為詞法變數,詞法變數的範圍就是詞法域;詞法變數是只限於所在範圍的局部變數;產生的詞法變數不在包的符號表內,只能在自身所在的塊中存在和訪問;使用my關鍵字聲明詞法變數的文法為:my (@Array);或my
Time of Update: 2018-12-03
一、引用的概念:Perl中提供了一種類似於C/C++語言中的指標功能的資料類型,名叫引用;這個引用與C++中的引用的概念不一樣,但是效果一樣;Perl中的引用就是指標,它用於跟蹤變數在記憶體中的地址,可以跟蹤簡單的標量變數、陣列變數、雜湊變數、檔案控制代碼變數,甚至還可以跟蹤子程式;引用存放的是某個變數在記憶體中的地址,這對於跟蹤大型的資料對象是很有用的;引用也是一種資料類型,這種類型的變數叫做引用變數,引用變數中存放的是記憶體位址,而不論被引用的資料對象是何種類型的資料對象,不論被引用的資料對
Time of Update: 2018-12-03
一、檔案位置重定位函數:1、rename()函數:檔案重新命名$Ret = rename(OldName,NewName);該函數用於把舊檔案名稱OldName重新命名為一個新的名字NewName,或者是把檔案OldName轉移到指定目錄NewName下面;兩個參數都可以為字串或者運算式;如果OldName與NewName同為檔案名稱或同為目錄名,而且OldName與NewName的目錄名完全相同,則該函數完成的式重新命名工作;如果OldName與NewName的檔案名稱相同,但是路徑不同,
Time of Update: 2018-12-04
作者: Mellonfire 2006-05-12 10:10:26<廣告> 你可能已經知道,Perl綜合典藏網(Comprehensive Perl Archive
Time of Update: 2018-12-03
#!/usr/bin/perl -w use strict;use LWP;use HTTP::Request::Common qw(POST GET); use HTTP::Cookies;use LWP::UserAgent; use LWP::Simple; use URI::URL;my $ua = LWP::UserAgent-> new; $ua-> agent( "Mozilla 1.503 Windows XP
Time of Update: 2018-12-03
#!/usr/bin/perl -w# Gist: https://gist.github.com/2928006use LWP::Simple;my $url=$ARGV[0];my $filename =$ARGV[1]; my $content = get($url) or die "Couldn't get $url";#$content =~ s#^.*?(<div.*?</div>).*$##m;if ($content =~ m#.*(<div
Time of Update: 2018-12-03
Submitted a question on StackOverflow just now. I intended to extract content from a web page which contains many unicode characters represented in the form of "%xx". As I used Perl module LWP to get web page, naturally handled these unicode
Time of Update: 2018-12-03
註: 網上找的一篇,為了備忘~(原帖http://www.weskers.com/tag/debug/) 下面進入正題,win下配置圖形化的debug環境,首先得有一個perl(汗,必須的),並配上環境變數然後到cmd下運行ppm install Tk(此過程保持連網)此後解壓附件裡的Devel-ptkdb-1.1092.tar.gz將裡面的ptkdb.pm複製到perlsitelibDevelptkdb.pm這就完成了,使用時第一個命令列參數應是 -d:ptkdb比如這樣perl
Time of Update: 2018-12-03
$total=0;$count=0;eval { $average = $total / $count ; print "xxx/n";} ; if ($@){ print "wrong /n";}else{ print "right/n";} eval塊的結束時的分號是必須的,因為不像 if或者while那樣的控制結構,eval實際上是個函數。但是代碼塊是真的塊,所以可以包括詞法變數("my"
Time of Update: 2018-12-03
1.Html中Tag提取<("[^"]*"|'[^']*'|[^'">])*>2.提取<a></a>標籤中的url和連結文本while ($Html =~ m{a\b([^>]+)>(.*?)</a>}ig){my $Guts = $1;my $Link = $2;if ($Guts =~ m{\b HREF#href屬性\s* =
Time of Update: 2018-12-04
#!C:/perl64/bin/perl require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my ($url_new,$url_old) = @ARGV; my $response = $ua->get($url_new); die $response->status_line unless
Time of Update: 2018-12-04
Perl語言中的變數有以下五種:標量,指標,數組,雜湊表(hash)和控制代碼。一、標量我們先來看看標量,標量是Perl語言中最簡單的一種資料類型。這種資料類型的變數可以是數字,字串,浮點數,不作嚴格的區分。在使用時在變數的名字前面加上一個“$”,表示是標量,相當於scalar中的第一個S。使用以下格式進行定義: $myfirst=123; #數字123 $mysecond="123";#字串123 $mythird="$myfirst,$mysecond";#字串123,123 $myfo
Time of Update: 2018-12-04
《Perl編程24學時教程》試題一、單選題1、以下哪一個字串直接量的定義方式是錯誤的( )(1)'thank you'(2)" "(3)"a "friend" of yours"(4)"a /"friend/" of yours"2、以下哪一條語句是錯誤的( )(1)$_= 'hello world';(2)$a='hello world';(3)my $b,$a='hello world';(4)my ($a,$b)=(0,'hello
Time of Update: 2018-12-04
一、簡介 模式指在字串中尋找的特定序列的字元,由反斜線包含:/def/即模式def。其用法如結合函數split將字串用某模式分成多個單詞:@array = split(/ /, $line); 二、匹配操作符 =~、!~ =~檢驗匹配是否成功:$result = $var =~ /abc/;若在該字串中找到了該模式,則返回非零值,即true,不匹配則返回0,即false。!~則相反。 這兩個操作符適於條件控制中,如: if ($question =~ /please/) { print
Time of Update: 2018-12-04
sub search_newarea{ my $ip =@_[0]; $start=1; $end=$count; @ips=split(/\./,$ip); $long_ip =int($ips[0])*256*256*256+int($ips[1])*256*256 + int($ips[2])*256 + int($ips[3]); while($start <= $end && $start >= 1 &
Time of Update: 2018-12-04
9.1搜尋標量用index進行搜尋index string,substringindex string,substring,start_positionindex函數從string的左邊開始運行,並搜尋substring.返回找到substring所在的位置。0是指最左邊的字元,如果沒有找到substring,index便返回-1;如:index "Ring around the rosy","around"; #返回5 index("Pocket full of posies","ket")