SlideShare ist ein Scribd-Unternehmen logo
1 von 20
私がPerlを使う理由



    日本オラクル株式会社
    畔勝(あぜかつ)洋平
twitter id: yoheia
blog: http://d.hatena.ne.jp/yohei-a/
私がPerlを使う理由
• 最初に触った言語(1998年頃、大学生のとき)
 • もしかしたら、JavaScript のほうが先だったかも。。。


• どこでも使える
 • Perl は Oracle Database (10g以降) に同梱されているのでWindows でも使
   える
 • 自由にソフトウェアをインストールできない環境で仕事をすることがあり
   ます


• 私の記憶力が悪い
 • awk、sed、grep などの正規表現の書き方などをそれぞれ覚えれない。
 • awk、sed、grep でできることはだいたい Perl でできる(たぶん)ので、
   Perl に絞ると覚えることを減らせる。


• 便利なライブラリがたくさんある
 • CPAN(Comprehensive Perl Archive Network)と呼ばれる巨大なアーカイブ
   に便利なライブラリがたくさんあります


• システムプログラミングができる
CPU使用率を 100% にする Perl ワンライ
  ナー

$ perl -e 'while(1) {}‘
CPU使用率を 100% にする Perl ワンライナー(2)

• CPUコアが4つの場合

$ for i in {1..4}
do
perl -e 'while(1){}' &
done
「ORA-」メッセージを番号別に集計する(1)
$ perl -nle '/(ORA-[0-9]+)/ and print $1;' alert_orcl.log | sort | uniq -
 c

↓実行結果

15 ORA-00001
20 ORA-01400
7 ORA-12899
 ...
「ORA-」メッセージを番号別に集計する(2)
$ perl -nle 'BEGIN{%h=();}/(ORA-[0-9]+)/ and
 $h{$1}++;END{map{print "$_:$h{$_}"} keys %h;}' alert_orcl.log

↓実行結果

ORA-00001:15              Perlのみで書いてみると
ORA-01400:20
ORA-12899:7
 ...
V$SYSSTAT から特定のデータベース統計情報の差
分を出す Perl ワンライナー
$ perl -F, -lane '/global cache blocks lost/ and
 printf(qq/%s,%sn/,$F[0],$F[2]-$tmp) and $tmp=$F[2]' sysstat.log

↓実行結果

0904235511,0
0904235541,1
0904235611,0
0904235642,3
0904235712,0
0904235742,5
0904235813,0
0904235843,0
V$SYSSTAT から特定のデータベース統計情報の差
分を出す Perl ワンライナー
$ perl -F, -lane 'printf(qq/%s,%s,%sn/,$F[1],$F[0],$F[2]-
 $h{$F[1]})if(exists($h{$F[1]}));$h{$F[1]}=$F[2]' sysstat.log
再帰的にファイル名に接頭辞をつける
↓実行前
$ find .
./a/bar.txt     CPANモジュールのFile::Findを使って、find
./a/foo.txt     コマンドに似たことをしている


↓実行
$ perl -MFile::Find -e 'find sub{rename($_,"prefix_$_") if -f},
 @ARGV' .

↓実行後
$ find .
./a/prefix_bar.txt
./a/prefix_foo.txt
テキストファイルの特定の行だけ表示する
• 1行目だけ表示する
perl -lne 'print if $.<2' file

• 10行目まで表示する
perl -pe 'exit if $. > 10' file

• 2行目から5行目まで表示する
perl -ne 'print if 2.. 5' file
レコードセパレータを変更する
• 行モード(デフォルト)
perl -e ...

• 段落モード(1つ以上の空行をレコードセパレータと認識す
  る)
perl -00 -e ...

• ファイルモード(ファイル全体を1レコードとして認識す
  る)
perl -0777 -e ...
カスタムフィールドセパレータを使う
• 空行をレコードセパレータ、改行コードをフィールドセパ
  レータに
perl -00 -F'n' -lane 'print $F[1] if($F[0] =~ /neo/)' hoge.txt



              awk 的な使い方
システムプログラミングはそれほどしていません
が。。。
最後に




      長い。。。
「あのー ワンライナーの意味わかってますか?」とコ
メントいただきました(^-^;
そんなときは -MO=Deparse でスクリプト化
$ perl -MO=Deparse -wnle 'BEGIN{%h=();}/(ORA-[0-9]+)/ and
  $h{$1}++;END{map{print "$_:$h{$_}"} keys %h;}' alert_orcl.log
BEGIN { $^W = 1; }
BEGIN { $/ = "n"; $ = "n"; }
LINE: while (defined($_ = <ARGV>)) {
   chomp $_;
   sub BEGIN {
     (%h) = ();
   }
   ++$h{$1} if /(ORA-[0-9]+)/;
   sub END {
     map {print "${_}:$h{$_}";} keys %h;
   }
   ;
}
-e syntax OK
私が参考にしているブログ
私が参考にしている書籍
ご清聴ありがとうございま
     した

Weitere ähnliche Inhalte

Was ist angesagt?

WebAPIではじめるphp入門
WebAPIではじめるphp入門WebAPIではじめるphp入門
WebAPIではじめるphp入門
Hiroaki Murayama
 
Ruby&Active Support for expert 3
Ruby&Active Support for expert 3Ruby&Active Support for expert 3
Ruby&Active Support for expert 3
xibbar
 
capistrano-colorized-stream
capistrano-colorized-streamcapistrano-colorized-stream
capistrano-colorized-stream
Naotoshi Seo
 
Write good parser in perl
Write good parser in perlWrite good parser in perl
Write good parser in perl
Jiro Nishiguchi
 
Perlで伝統芸能
Perlで伝統芸能Perlで伝統芸能
Perlで伝統芸能
hitode909
 
Google Perf Tools (tcmalloc) の使い方
Google Perf Tools (tcmalloc) の使い方Google Perf Tools (tcmalloc) の使い方
Google Perf Tools (tcmalloc) の使い方
Kazuki Ohta
 

Was ist angesagt? (20)

姫路IT系勉強会 Vol.11 第0回L-1グランプリ bash
姫路IT系勉強会 Vol.11 第0回L-1グランプリ bash姫路IT系勉強会 Vol.11 第0回L-1グランプリ bash
姫路IT系勉強会 Vol.11 第0回L-1グランプリ bash
 
WebAPIではじめるphp入門
WebAPIではじめるphp入門WebAPIではじめるphp入門
WebAPIではじめるphp入門
 
Wakateweb 10
Wakateweb 10Wakateweb 10
Wakateweb 10
 
ターミナル上でのSwift運用
ターミナル上でのSwift運用ターミナル上でのSwift運用
ターミナル上でのSwift運用
 
ターミナル上でのSwift運用 ver.1.1
ターミナル上でのSwift運用 ver.1.1ターミナル上でのSwift運用 ver.1.1
ターミナル上でのSwift運用 ver.1.1
 
Ruby&Active Support for expert 3
Ruby&Active Support for expert 3Ruby&Active Support for expert 3
Ruby&Active Support for expert 3
 
capistrano-colorized-stream
capistrano-colorized-streamcapistrano-colorized-stream
capistrano-colorized-stream
 
Hostsの活用
Hostsの活用Hostsの活用
Hostsの活用
 
pecoを使おう
pecoを使おうpecoを使おう
pecoを使おう
 
systemdでよく使うサブコマンド
systemdでよく使うサブコマンドsystemdでよく使うサブコマンド
systemdでよく使うサブコマンド
 
[20110129] sphinx theme collection 2011春
[20110129] sphinx theme collection 2011春[20110129] sphinx theme collection 2011春
[20110129] sphinx theme collection 2011春
 
Mac_Terminal_ver1.0
Mac_Terminal_ver1.0Mac_Terminal_ver1.0
Mac_Terminal_ver1.0
 
Write good parser in perl
Write good parser in perlWrite good parser in perl
Write good parser in perl
 
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
 
Perlで伝統芸能
Perlで伝統芸能Perlで伝統芸能
Perlで伝統芸能
 
メタメタプログラミングRuby
メタメタプログラミングRubyメタメタプログラミングRuby
メタメタプログラミングRuby
 
シェルスクリプトを使って日々の作業を 効率アップする方法と UNIX 文化のあれこれ。
シェルスクリプトを使って日々の作業を 効率アップする方法と UNIX 文化のあれこれ。シェルスクリプトを使って日々の作業を 効率アップする方法と UNIX 文化のあれこれ。
シェルスクリプトを使って日々の作業を 効率アップする方法と UNIX 文化のあれこれ。
 
Rpn and forth 超入門
Rpn and forth 超入門Rpn and forth 超入門
Rpn and forth 超入門
 
Sounds Like Common Lisp - ゼロからはじめるサウンドプログラミング
Sounds Like Common Lisp - ゼロからはじめるサウンドプログラミングSounds Like Common Lisp - ゼロからはじめるサウンドプログラミング
Sounds Like Common Lisp - ゼロからはじめるサウンドプログラミング
 
Google Perf Tools (tcmalloc) の使い方
Google Perf Tools (tcmalloc) の使い方Google Perf Tools (tcmalloc) の使い方
Google Perf Tools (tcmalloc) の使い方
 

Andere mochten auch (7)

Webを支える技術 1章 webとは何か?
Webを支える技術 1章 webとは何か?Webを支える技術 1章 webとは何か?
Webを支える技術 1章 webとは何か?
 
クラスとクラスの依存を薄くする
クラスとクラスの依存を薄くするクラスとクラスの依存を薄くする
クラスとクラスの依存を薄くする
 
PostgreSQL Internals (1) for PostgreSQL 9.6 (English)
PostgreSQL Internals (1) for PostgreSQL 9.6 (English)PostgreSQL Internals (1) for PostgreSQL 9.6 (English)
PostgreSQL Internals (1) for PostgreSQL 9.6 (English)
 
監査ログをもっと身近に!〜統合監査のすすめ〜
監査ログをもっと身近に!〜統合監査のすすめ〜監査ログをもっと身近に!〜統合監査のすすめ〜
監査ログをもっと身近に!〜統合監査のすすめ〜
 
簡単!AWRをEXCELピボットグラフで分析しよう♪
簡単!AWRをEXCELピボットグラフで分析しよう♪簡単!AWRをEXCELピボットグラフで分析しよう♪
簡単!AWRをEXCELピボットグラフで分析しよう♪
 
Oracle Database Connect 2017 / JPOUG#1
Oracle Database Connect 2017 / JPOUG#1Oracle Database Connect 2017 / JPOUG#1
Oracle Database Connect 2017 / JPOUG#1
 
進化したのはサーバだけじゃない!〜DBA の毎日をもっと豊かにするユーティリティのすすめ〜
進化したのはサーバだけじゃない!〜DBA の毎日をもっと豊かにするユーティリティのすすめ〜進化したのはサーバだけじゃない!〜DBA の毎日をもっと豊かにするユーティリティのすすめ〜
進化したのはサーバだけじゃない!〜DBA の毎日をもっと豊かにするユーティリティのすすめ〜
 

Ähnlich wie 私がPerlを使う理由

Modern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI SeminarModern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI Seminar
Sotaro Karasawa
 

Ähnlich wie 私がPerlを使う理由 (20)

20年越しで Perl 4 to 5 した話
20年越しで Perl 4 to 5 した話20年越しで Perl 4 to 5 した話
20年越しで Perl 4 to 5 した話
 
Perl勉強会#2資料
Perl勉強会#2資料Perl勉強会#2資料
Perl勉強会#2資料
 
What is chef
What is chefWhat is chef
What is chef
 
ページャ lessを使いこなす
ページャ lessを使いこなすページャ lessを使いこなす
ページャ lessを使いこなす
 
初めてのPerl
初めてのPerl初めてのPerl
初めてのPerl
 
知って得する標準関数の使い方
知って得する標準関数の使い方知って得する標準関数の使い方
知って得する標準関数の使い方
 
最新PHP事情 (2000年7月22日,PHPカンファレンス)
最新PHP事情 (2000年7月22日,PHPカンファレンス)最新PHP事情 (2000年7月22日,PHPカンファレンス)
最新PHP事情 (2000年7月22日,PHPカンファレンス)
 
Yohes kitchen
Yohes kitchenYohes kitchen
Yohes kitchen
 
04 filesystem include
04 filesystem include04 filesystem include
04 filesystem include
 
Lisp Tutorial for Pythonista Day 6
Lisp Tutorial for Pythonista Day 6Lisp Tutorial for Pythonista Day 6
Lisp Tutorial for Pythonista Day 6
 
Modern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI SeminarModern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI Seminar
 
Pythonista も ls を読むべきか?
Pythonista も ls を読むべきか?Pythonista も ls を読むべきか?
Pythonista も ls を読むべきか?
 
Niigata.pm #1
Niigata.pm #1Niigata.pm #1
Niigata.pm #1
 
PHP基礎勉強会
PHP基礎勉強会PHP基礎勉強会
PHP基礎勉強会
 
モダンmod_perl入門 #yapcasia
モダンmod_perl入門 #yapcasiaモダンmod_perl入門 #yapcasia
モダンmod_perl入門 #yapcasia
 
NPCA夏合宿 2014 講義資料
NPCA夏合宿 2014 講義資料NPCA夏合宿 2014 講義資料
NPCA夏合宿 2014 講義資料
 
Ansible meetup201409
Ansible meetup201409Ansible meetup201409
Ansible meetup201409
 
誰でも出来るosxでのローカルなウェブ開発環境構築
誰でも出来るosxでのローカルなウェブ開発環境構築誰でも出来るosxでのローカルなウェブ開発環境構築
誰でも出来るosxでのローカルなウェブ開発環境構築
 
PerlのTwitterモジュールの紹介 #twtr_hack
PerlのTwitterモジュールの紹介 #twtr_hackPerlのTwitterモジュールの紹介 #twtr_hack
PerlのTwitterモジュールの紹介 #twtr_hack
 
PHPカンファレンス2014の懇親会飛び込みLT資料
PHPカンファレンス2014の懇親会飛び込みLT資料PHPカンファレンス2014の懇親会飛び込みLT資料
PHPカンファレンス2014の懇親会飛び込みLT資料
 

Mehr von Yohei Azekatsu

Dbts2012 unconference wttrw_yazekatsu_publish
Dbts2012 unconference wttrw_yazekatsu_publishDbts2012 unconference wttrw_yazekatsu_publish
Dbts2012 unconference wttrw_yazekatsu_publish
Yohei Azekatsu
 

Mehr von Yohei Azekatsu (8)

Linux Process Snapper Introduction
Linux Process Snapper IntroductionLinux Process Snapper Introduction
Linux Process Snapper Introduction
 
CloudTrail ログの検索を爆速化してみた
CloudTrail ログの検索を爆速化してみたCloudTrail ログの検索を爆速化してみた
CloudTrail ログの検索を爆速化してみた
 
Parquetはカラムナなのか?
Parquetはカラムナなのか?Parquetはカラムナなのか?
Parquetはカラムナなのか?
 
Linux Performance Analysis in 15 minutes
Linux Performance Analysis in 15 minutesLinux Performance Analysis in 15 minutes
Linux Performance Analysis in 15 minutes
 
iostatの見方
iostatの見方iostatの見方
iostatの見方
 
シンプルでシステマチックな Oracle Database, Exadata 性能分析
シンプルでシステマチックな Oracle Database, Exadata 性能分析シンプルでシステマチックな Oracle Database, Exadata 性能分析
シンプルでシステマチックな Oracle Database, Exadata 性能分析
 
シンプルでシステマチックな Linux 性能分析方法
シンプルでシステマチックな Linux 性能分析方法シンプルでシステマチックな Linux 性能分析方法
シンプルでシステマチックな Linux 性能分析方法
 
Dbts2012 unconference wttrw_yazekatsu_publish
Dbts2012 unconference wttrw_yazekatsu_publishDbts2012 unconference wttrw_yazekatsu_publish
Dbts2012 unconference wttrw_yazekatsu_publish
 

私がPerlを使う理由