本公眾號(hào)【讀芯樹:duxinshu_PD】主要介紹數(shù)字集成電路物理設(shè)計(jì)相關(guān)知識(shí),才疏學(xué)淺,如有錯(cuò)誤,歡迎指正交流學(xué)習(xí)。 這是集成電路物理設(shè)計(jì)的第七個(gè)系列【腳本語言】的第十八篇文章,本篇文章主要介紹perl相關(guān)內(nèi)容: 01 — 目錄操作 #顯示目錄下的所有tcl的文件 $dir='/home/user/*.tcl'; my @files=glob($dir); foreach (@files) { print '$_\n'; } opendir (DIR, '/home/user/scr') or die 'no this dir: $!'; foreach (sort grep(/^.*\.tcl$/, readdir(DIR))) { print '$_\n'; } closedir DIR; #創(chuàng)建一個(gè)新目錄 $dir='/tmp/new_folder'; mkdir ($dir) or die 'no create $dir, $!'; #刪除目錄 $dir='/tmp/new_folder'; rmdir ($dir) or die 'no create $dir, $!'; #切換目錄 chdir ($dir) or die 'no change $dir, $!'; 02 — 特殊變量
03 — 正則表達(dá)式 m// #匹配 =~表示匹配, !~表示不匹配 i: 忽略大小寫;m:多行模式;o:僅賦值一次;s:但行模式;x:忽略模式中空白;g:全局匹配;cg:全局匹配失敗后,允許再次查找。 $` #匹配部分的前一部分字符串 $& #匹配字符串 $' #匹配字符剩余的部分 #匹配 $str='this is a string'; if ($str=~/is/) { print 'pattern is found!\n' }
s/old/new/ #替換 i:忽略大小寫;m:行開頭和結(jié)尾是“^”和“$”; s:'.'包括換行符;x:忽略空白符;g:替換所有匹配字符串。 $str='this is a string'; $str=~s/this/that/; #將this替換為that print '$str\n';
tr/// #轉(zhuǎn)化 c:轉(zhuǎn)化所有未制定字符;d:刪除所有指定字符;s:將多個(gè)相同的輸出字符合并一個(gè)。 $str='this is a string'; $str=~tr/a-z/A-Z/; #將小寫轉(zhuǎn)化為大寫 $str=~tr/\t / /d; #將tab空格刪除 $str=~tr/0-9/ /cs; #提取數(shù)字 04 — 正則表達(dá)式2
05 — 進(jìn)程管理 #反引號(hào):可以執(zhí)行Unix命令 $dir='/home/user/tmp/'; chdir ($dir) or die 'no change $dir, $!'; @files=`ls -trl`; foreach $file (@files) { print $file; } 06 — 參考文獻(xiàn)
|
|