"codesnipet(無料)タグ投稿記事"

Perl One Liner

1 28、2009 / / alexken作成/ / 技術 / / No Comments

主にわざがテキストを持ってジョムルラク距離はだろう、
Unixでfind、sed、awkを組み合わせてオジガン閑居は
bash / perl / ruby​​まで行かずに処理しているが、

ファイルを開いて、変更して、再保存するには、openしたファイルとsaveするファイルが同一なので、
パイプ(|)を使用してtmpファイルを作成していますが、
find-execの中のパイプを使うことができなくてこのような時は、perl one linerが適当である。

よく使うPerl one liner。

find。 -name "file *"-exec perl-i-pe 's | BEFORE | AFTER | g' {};

その他のperl one liner
リンク1リンク2

[java] reflect on java

11 13、2007 / / alexken作成/ / 技術 / / No Comments

フェサソClassを調べることがあるがreflectをカモクオソしばらくgooglingて再度学習...

java.lang.Stringのmethodを出力するルーチンのゴルジャマン要約すると....

; import java.lang.reflect。*;

public class ClassExam {

printClassInfo ( String className ) { public void printClassInfo(String className){
try {
this . getClass ( ) . getClassLoader ( ) . loadClass ( className ) ; Class a = this。getClass()。getClassLoader()loadClass(className);
methods = a. getDeclaredMethods ( ) ; Method [] methods = a。getDeclaredMethods();
int i = 0 ; i < methods. length ; i ++ ) { for(int i = 0; i <methods。length; i + +){
. println ( methods [ i ] . toString ( ) ) ; System。out。println(methods [i]。toString());
}
( Exception e ) { } catch(Exception e){
}
}

main ( String [ ] args ) { public static void main(String [] args){
ClassExam ( ) ; ClassExam a = new ClassExam();
"java.lang.String" ) ; a。printClassInfo( "java.lang.String");
}
}

PerlでGetopt :: Stdを使用する

8 30、2006 / / alexken作成/ / 技術 / / No Comments

Unixスタイルのプログラムパラメータの処理をしてくれるモジュールがGetoptなのに
頻繁に使用してみるとcodesnipetに使用しようと、私が使用するテンプレートをここに登録しておく。

main :: HELP_MESSAGE()、main :: VERSION_MESSAGE()

を実装しておくと - help、 - versionオプションに反応して、getopts(c:hv)に使用するオプションの一覧を表示してください。
上記の例ではcの後に:の意味は、パラメータを受け取るという意味である。
入力されたパラメータは、$ Getopt :: Std :: opt_cとして使用することができます。

#!/ usr / bin / perl
#vim:set sw = 4 ts = 4 si et nu:

use strict;
Std ; use Getopt :: Std;

################################################## ######
#Global settings
################################################## ######
Std :: STANDARD_HELP_VERSION = 1 ; $ Getopt :: Std :: STANDARD_HELP_VERSION = 1;

VERSION_MESSAGE ( ) { sub main :: VERSION_MESSAGE(){
; print "$ 0 Version 0.5 hyeonkwen@gmail.com";
}

HELP_MESSAGE ( ) { sub main :: HELP_MESSAGE(){
print << END;
Description of this program。
Usage:$ 0 OPTION DIRECTORY

OPTION
-c description of c option
-h view help message
-v view version information
END
}

################################################## ######
#main()
################################################## ######

sub main(){
! getopts ( "c:hv" ) || $Getopt :: Std :: opt_h ) { if(!getopts( "c:hv")| | $ Getopt :: Std :: opt_h){
( ) ; main :: HELP_MESSAGE();
exit;
( $Getopt :: Std :: opt_v ) { } elsif($ Getopt :: Std :: opt_v){
( ) ; main :: VERSION_MESSAGE();
exit;
}
}

main();

ブログのカテゴリ

天体写真ギャラリー