Time of Update: 2018-12-08
perl中建立數組時,可以使用到qw。但有一個問題,如果要建立有20個人名組成的數組,並且每個人的名字是這種形式的"Join smith" "Harry Potter"也就是每一個名字既包含姓也包含名。此時,qw就不起作用了。因為qw是用空格作為分隔字元。下面提供一些替代的解決方案,供大家參考。方案一:用最原始的方案,也就是雙引號,來進行數組的建立複製代碼 代碼如下:@names=("Join smith","Harry Potter"); print @names[0]; 結果如下:F:\&
Time of Update: 2018-12-07
Perl Unicode轉換概括:1.判斷輸入源的編碼方式2.輸入源是utf8編碼 a. Encode::_utf8_on($str);開啟utf8 flag。 輸入源非utf8編碼 a. $string = decode(ENCODING,$octets [,CHECK]);將輸入源轉化成utf8編碼並開啟utf8 flag3.輸出 $str = Encode::encode(ENCODING, $str);把字串從utf8編碼轉成指定的編碼, 並關閉utf8 flag-----
Time of Update: 2018-12-08
需求:取檔案1中的一行,和檔案2中所有的資料進行比較,有相同的儲存起來,否則刪除。複製代碼 代碼如下:#!/usr/bin/perl#use strict;open(FILE1,"C:/Perl/BX/BX-Users.txt");open(FILE2,"C:/Perl/BX/BX-Book-Ratings.txt");open(result1,">C:/perl/BX/BX-Users_result.txt");my $i=0;my $j=0;while((my $bxUser=<
Time of Update: 2018-12-08
按照要求進行的排序:複製代碼 代碼如下:#!/bin/perl@number=qw/5 10 15 3 2 4 8 6 /; my @descending =sort {$a<=>$b} @number;#這裡$a=5,$b=10,因為$a在前,perl得到的結果是小數在前,也就是升序排列 print "@descending\n"; 結果如下:F:\>perl\a.pl 2 3 4 5 6 8 10 15 F:\>
Time of Update: 2018-12-08
複製代碼 代碼如下:#!/usr/bin/perl#use strict;open(FILE1,"C:/Perl/BX/BX-Users.csv");open(FILE2,"C:/Perl/BX/BX-Books.csv");open(FILE3,"C:/Perl/BX/BX-Book-Ratings.csv");open(result1,">C:/Perl/BX/BX-Users.txt");my %table;my $record1;my $count1;#my
Time of Update: 2018-12-08
複製代碼 代碼如下:#!/usr/bin/perl -wuse strict;use warnings;use FileHandle;my %fh;my @array = (1..10);for(1..5){ open $fh{$_},">$_.txt" or die;}for(1..5){ #print $fh{$_} "$_\n"; 此處錯誤 $fh{$_}->print( "$_\n" ); #為FileHandle裡的函數
Time of Update: 2018-12-07
使用Regex分兩步走: 先去掉前面的: $a=~s/^ +//; 在去掉後面的: $a=~s/ +$//; 一步就可以: s/(^s+|s+$)//g; 刪除字串末尾的換行:chomp函數通常會刪除變數裡包含的字串尾部的分行符號。它是chop函數的一個略微安全些的版本,因為它對沒有分行符號的字串沒有影響。更準確地說,它根據瞭解$/的當前值刪除字串終止符,而不只是最後一個字元。和chop不同,chomp返回刪除的字元數量。 完!
Time of Update: 2018-12-07
代碼: #!/usr/local/bin/perl use CGI ':standard'; print header; print start_html("Example CGI.pm Form"); print "<h1> Example CGI.pm Form</h1>\n"; print_prompt(); do_work(); print_tail(
Time of Update: 2018-12-07
來自:http://www.perlfect.com/articles/sorting.shtml perl 比較操作符列表: NumbersStrings<lt>gt<=le>=ge==eq<=>cmp!=ne <=> 和cmp的詳細解釋: Relation of $a and $bValue Returned by $a <=>$a greater than $b1$a equal to $b0$a less than
Time of Update: 2018-12-07
轉自:http://perl.apache.org/docs/general/perl_reference/perl_reference.html use(), require(), do(), %INC and @INC Explained The @INC array@INC is a special Perl variable which is the equivalent of the shell's PATH variable. Whereas PATH contains a
Time of Update: 2018-12-07
Programming Perl (1180 pages).pdf Teach Yourself Cgi Programming With Perl Perl Cookbook, 2nd Ed (2003) TeamLiB good.chm Network Programming with Perl Advanced Perl Programming 2nd(O'Reil 2005).chm Perl Hacks Higher-Order Perl--A
Time of Update: 2018-12-07
代碼:需要顯式地定義變數且初始化。例如optionX。如果沒有定義變數且顯式初始化,且沒有在命令列指定選項,則選項對應的變數將為未定義。 #!/bin/perl-5.8.3/bin/perl$use warnings;$use strict;$use Data::Dumper;$use Getopt::Long;$use Pod::Usage;$our $g_opts;our $optionX=''; #if not defined in command line, it will be emp
Time of Update: 2018-12-07
最近在用Perl來做工作的時候,運行到一個地方,需要我輸入一個裝置名稱,以判斷接下來應該做的步驟。每次運行到這裡,我都是手動輸入很長的裝置名稱,比如說ciscocontenteng,每次這樣輸入,不僅累死人,還很容易出錯。這種情況下,可以用Term::Complete這個module來實現用tab鍵自動補全。用法非常簡單,看代碼就差不多能理解了:use warnings; use strict;use Term::Complete;my @completion_list = (“atest”,”
Time of Update: 2018-12-07
補充一下昨天總結的查詢本地已經安裝了哪些 Perl 模組的方法,還有兩種方法可以用:在 shell 裡運行下面的語句:$ perl -mSmart::Comments -el 如果提示了類似下面的錯誤, Can’t locate Smart/Comments.pm in @INC (@INC contains: c:/strawberry/perl/lib c:/strawberry/perl/site/lib .).則表明你的 Perl
Time of Update: 2018-12-07
怎麼使用Perl指令碼作業系統環境變數? 機靈的朋友立馬就會想到Perl中提供的$ENV這個特殊的雜湊變數,對,在$ENV中完全可以擷取到一些系統變數。怎麼擷取呢?比如想要知道Path這個系統內容變數的內容,我們可以通過$ENV{'Path'} 來擷取。如果想設定Path這個環境變數呢,哈,使用$ENV{'Path'}=‘C:\Windows\System32’來設定。想擷取所有的環境變數列表也很簡單,雜湊遍曆不就可以了~
Time of Update: 2018-12-07
最近一直的為一些技術和語言搞過去搞過來,沒得時間來更新這個地方..非常的慚愧..前段時間,花了很長的時間來學習.net3.0,3.5等相關的一些東西,包括linq,lamabda等等...在看這些東西的時候,和開發組組長激烈的吵了一架,總算把公司從2005推到了2008開發上.(06年進公司的時候,還在用2003).同時,由於自己個人在私下的時間內,在為公司做一個培訓的內部網站(還在使用05的模板頁),說實話,自己感覺,對一些技術等嚴重的落後..沒辦法,分公司不象北京,上海,廣州
Time of Update: 2018-12-07
copy from http://www.lwolf.cn/blog/article/program/perl-ini.html之前有寫過用C#解析INI檔案的文章,那時是因為要用Perl來解析INI,後來就在網上找了個現成的解析代碼IniParser. 假設INI檔案是這樣的:[Directories]Input=c:\autoexec.bat 使用方法如下:use IniParser;my $ini = IniParser->new("c:\\test.ini")
Time of Update: 2018-12-07
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#找到輸入的檔案清單,返回一個數組sub arr_argv_file{ my @arr_fname = @_; my @arr_file_list; foreach $list(@arr_fname){ chomp($list);
Time of Update: 2018-12-07
1、perldoc perllocal 2、推薦pmtools裡的pminst命令 http://search.cpan.org/src/MLFISHER/pmtools-1.01/pminst 3、編寫如下標本#!/usr/bin/perluse strict;use ExtUtils::Installed;my $inst= ExtUtils::Installed->new();my @modules = $inst->modules();foreach(@modules)
Time of Update: 2018-12-07
一,基於單純的密碼驗證的情況:1.安裝Net::SSH::Perl模組,安裝方法參照Perl模組安裝。2.自動登入例子,我要用testuser使用者登陸到伺服器192.168.0.100執行df命令:#!/usr/bin/perl -wuse strict;use Net::SSH::Perl;my $host = '192.168.0.196';my $user = 'root';my $password = 'pass';my $ssh =