Time of Update: 2018-07-25
將“use POSIX ":sys_wait_h";”去掉,還有在主進程中列印子進程中的變數是不對的,主進程不知道子進程的狀況,除非你用pipe將變數值傳給主進程,###################################################!/usr/bin/perl#use POSIX ":sys_wait_h";my $a=10;for($i=1;$i<=3;$i++){my $pid=fork(); if
Time of Update: 2018-07-25
用perl調度sql指令碼,在開多個進程的時候,發現perl寫入的log檔案先後次序紊亂,又不想搞多線程編程那麼麻煩,我的處理方法,對應的檔案加鎖。perl提供flock函數對檔案控制代碼加鎖。 參考代碼: use Fcntl qw(:flock); my $sum; my $kk=$ARGV[0]; open wr , ">>/wls/dsadm/etl/test.txt" ; flock(wr, LOCK_EX); for($
Time of Update: 2018-07-24
my (@frames,@button);my %sub_of = ( "日誌查詢" => \&push_button2 , "簡訊查詢" => \&push_button3 , "VIEW DISK" => \&push_button4 , 4 => sub{ print "program 4" }, 5
Time of Update: 2018-07-26
[root@localhost mha4mysql-node-0.52]# perl Makefile.PL;make;make install Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: inc /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl
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-26
#!/usr/bin/perl -wuse strict;use Net::SMTP;use Authen::SASL;(在SMTP伺服器上要求使用者認證,必須的模組)BEGIN {push (@INC,'/usr/lib/perl5/5.8.8/Net/ '); } my $from = 'huashan125@huashan.peonymao.com';my $to = 'peonymao@orrisintl.com';my $username = 'huashan125';my $
Time of Update: 2018-07-26
1, 在不需要認證的smtp伺服器上發送郵件 #!/usr/bin/perl -w use Net::SMTP; $smtp = Net::SMTP->new($mail_server); #郵件伺服器地址 $smtp->mail($send_user);
Time of Update: 2018-07-26
在其他論壇看了很多關於Perl模組的安裝,其實有時候很容易出現安裝失敗。 尤其是在WINDOWS上,比如可以使用CPAN,PPM等工具方式。在命令列 中輸入CPAN, 彈出CPAN> ,然後可以輸入INSTALL 模組名,比如我要安裝LWP::UserAgent::ProxyAny 輸入install LWP::UserAgent::ProxyAny,可是經常會有錯誤,這個方式非常麻煩。於是exit;轉到PPM,
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-07-29
http://developer.51cto.com/art/201007/213719.htm http://www.ibm.com/developerworks/cn/linux/sdk/perl/culture-4/index.html http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perldebug.html#NAME
Time of Update: 2018-07-29
在文本處理時經常會碰到這樣的情況:有一批檔案需要修改裡面的內容,但是又希望保留原來檔案的內容。這個時候Perl提供了一個很方便的變數$^I,將需要備份檔案的尾碼儲存在該變數後,我們在修改檔案內容時,Perl會: 1、先將原檔案開啟並另存新檔以“原檔案名稱+$^I存放的尾碼字元”為檔案名稱的備份檔案。 2、在原檔案上修改。 例如下面一段程式,我要將所有.dat文本中的abc改為dfg,並備份成.bak的檔案
Time of Update: 2018-12-03
grep返回一個數字中合格所有元素;map對數字中所有元素實施轉化並返回結果。兩者都遍曆了數組,但一個用來搜尋,一個用來轉化。兩者都支援運算式或者代碼塊。#!/usr/bin/perl -wuse strict;#get positive numbermy @number = (1,2,3, -1,-5);my @positive_number = grep $_ > 0, @number;print "\@number: (@number)\n";print
Time of Update: 2018-12-03
1、先瞭解/proc/stat檔案資訊 在Linux/Unix下,CPU利用率分為使用者態,系統態和空閑態,分別表示CPU處於使用者態執行的時間,系統核心執行的時間,和空閑系統進程執行的時間。平時所說的CPU利用率是指:CPU執行非系統空閑進程的時間 / CPU總的執行時間。 此資訊都儲存在/proc/stat檔案中, 在Linux的核心中,有一個全域變數:Jiffies。
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-03
作為軟體開發人員,有時需要對伺服器上的某些進程進行監控,以便掌握伺服器的運行情況。因此當出現異常情況時,郵件提示是個不錯的選擇,可使開發維護人員及時進行維護處理。1:利用Mail::Sendmail發送普通郵件#!/usr/bin/perluse strict;use Mail::Sendmail;sendmail(From =>
Time of Update: 2018-12-04
use Net::SMTP;my $email_server = 'smtp.163.com';my $email_receivers = 'aaa@163.com';my $email_sender = ‘aaa@163.com';$email_body = ’hello‘;sub sendMail{ my $smtp = Net::SMTP->new($email_server); $smtp->mail($email_sender);
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
#!/usr/bin/perl -wuse strict;use 5.010;sub BigHeapAdjust($$/@){ my($pos, $len, $arr) = @_; my $temp = $arr->[$pos]; #沿節點值較大的兒子往下層篩選,2*r+1是左兒子,2*(r+1)是右兒子 for(my $j = 2*$pos+1; $j <= $len-1; $j = 2*$j+1 ) { $j++ if $j<$len-
Time of Update: 2018-12-04
mygrep:搜尋字串在某個檔案dir內,包括內部所有的子檔案夾,Win和*nix通用 1#!/usr/bin/perl 2 3 use strict; 4 use File::Spec::Functions; 5 6 my %usage={}; 7 $usage{"name"}="mygrep"; 8 $usage{"version"}="0.1"; 9 $usage{"author"}="xxx002";10
Time of Update: 2018-12-04
#!/usr/bin/perl# un-mangle c++ symbol# assuming the c++filt command is availableuse strict;use warnings;if ($#ARGV != 0) { print "usage:\n"; print "program filename\n";}my $in_filename = $ARGV[0]; open(my $in, "<", $in_filename) or die "Can'