夕口技術錄
專業上的小常識,備而用之~
Category Archives: Perl
[Linux][Perl] – 文字取代
2008/12/17
Posted by 於 取代法1: perl -pe ‘s/<?/<?php/g’ 檔名
取代法2: perl -pe ‘s/<\?/<\?php/g’ action.php > action-new.php
能將所有目錄中.你想取代的檔案都取代到
取代法3: perl -i -pe ‘s/<\?/<\?php/g’ `find . -iname ‘*htm*’`
取代法3 後面的 find.. 可以改用其它你想改的檔名(ex: 改成 *.php)
[Linux][perl][sed] – 超快速 search and replace
2008/12/17
Posted by 於 上次 在 sed 的文章中談過,
如何使用 sed 快速進行 replace (#sed -i ‘s/aaaa/4444/g’ testfile (將 testfile檔案內的 aaaa 替換成 4444))
而如用何 sed 進行 search and display 呢?
sed -n ‘s/La/Oo/gp’ testfile
g 表全部進行比較,把 La 全換成 Oo
p 表顯示有被置換的行
而perl又是如何用呢 ?
perl -pi -e ‘s/src_str/new_str/g’ testfile
以上指令會將目錄下所有 testfile 檔案更新,用 “new_str" 替換 “src_str"。
[Linux][Perl] – 產生一組亂碼
2008/11/19
Posted by 於 用 Perl 實現:
$ perl -e ‘print crypt(“password", “zz“), “\n";’
[Linux][perl][find] – 一次刪除所有空目錄的方法
2008/11/19
Posted by 於 方法一:用 Perl 實現
程序
#!/usr/bin/perl
use File::Find;
finddepth(sub{rmdir},’.’)
命令
perl -MFile::Find -e"finddepth(sub{rmdir},’.’)"
方法二:用 Shell Script 實現
find -depth -type d -empty -exec rmdir {} \;
以上方法來自:http://duramecho.com/ComputerPrograms/DeleteEmptyDirectories/index.html
[Perl] – 在Perl程序中關閉輸入回顯功能
2008/11/19
Posted by 於 會想到這個功能,
主要是之前一個朋友向我提問如何可以做到,
當時沒有想到方法,
現在有啦 ^^
使用 Perl 來進行,
若有輸入密碼的功能,
或許不想讓輸入的內容回顯到屏幕上,
可以用stty命令讓echo無效。
#!/usr/bin/perl
system(“stty -echo");
print “Enter your password: “;
chomp($passwd = <>);
print “\n(Test) Your password is $passwd\n";
system(“stty echo");
print “Enter your password: “;
chomp($passwd = <>);
print “\n(Test) Your password is $passwd\n";
system(“stty echo");
近期迴響