ラベル:ImageMagic Perl
2013年02月19日
2012年08月06日
DBIx::Class::Storage::Statisticsのインストール
cpanm DBIx::Class::Storage::Statistics
でこける。
テスト接続が上手くいかないだけで、たぶん大丈夫だからむりやりインストールする
makeつくったら、
make cleanをする
でこける。
テスト接続が上手くいかないだけで、たぶん大丈夫だからむりやりインストールする
makeつくったら、
make cleanをする
2012年07月09日
perlでヘッダー出力リスト
http://www.futomi.com/lecture/form/cgi-pm.html#s4
記述例 | 出力内容 |
---|---|
print $q->header; | Content-Type: text/html |
print $q->header('image/gif'); | Content-Type: image/gif |
print $q->header('text/html','204 No response'); | Status: 204 No response Content-Type: text/html |
print $q->header(-type=>'image/gif', -nph=>1, -status=>'402 Payment required', -expires=>'+3d', -cookie=>$cookie, -charset=>'utf-7', -attachment=>'foo.gif', -Cost=>'$2.00'); | HTTP/1.0 402 Payment required Status: 402 Payment required Set-Cookie: Expires: Tue, 06 Mar 2001 09:26:31 GMT Date: Sat, 03 Mar 2001 09:26:31 GMT Attachment: foo.gif Charset: utf-7 Cost: $2.00 Content-Type: image/gif |
2012年07月04日
改行コードのお話
OSの違い
・UNIX → LF
・Windows → CR+LF
・Mac → CR
スマフォについて
・アンドロイド → Linux系なので、たぶんLF
・iPhone → Mac系、たぶんCR
・WindowsCE → たぶんCR+LF
を踏まえて、改行コードを統一させるperコード
(最後は
に変換してます)
$val =~ s/\r\n/\r/g;
$val =~ s/\n/\r/g;
$val =~ s/\r/
/g;
・UNIX → LF
・Windows → CR+LF
・Mac → CR
スマフォについて
・アンドロイド → Linux系なので、たぶんLF
・iPhone → Mac系、たぶんCR
・WindowsCE → たぶんCR+LF
を踏まえて、改行コードを統一させるperコード
(最後は
に変換してます)
$val =~ s/\r\n/\r/g;
$val =~ s/\n/\r/g;
$val =~ s/\r/
/g;
2012年06月21日
正規表現
● iオプションは、大文字・小文字を区別する
/ssss/i
●こんな事もできる
if ($str =~ /@pattern/){
print "$str\n";
}
/ssss/i
●こんな事もできる
if ($str =~ /@pattern/){
print "$str\n";
}
2012年06月20日
eqと==の違い
http://abe-log.cocolog-nifty.com/blog/2007/08/eqperl_b555.html
ですって。
01 と1はどうでしょう?
==は数値比較に使用します。
eqは文字列比較に使用します。
ですって。
01 と1はどうでしょう?
2012年06月07日
Xslateについて
TT2Likeのマニュアル
http://search.cpan.org/~gfuji/Text-Xslate-1.5012/lib/Text/Xslate/Syntax/TTerse.pm
↓こちらも参考になる模様
http://www.alink.co.jp/tech/blog/2010/09/01/perl-sledge%E3%81%A7textxslate%E3%82%92%E4%BD%BF%E3%81%86/
テンプレートに渡した値が、自動でエスケープされてて
オプションないのかって探したとき。
↓
http://d.hatena.ne.jp/gfx/20100822/1282469200
typeオプションでtextを指定すると出来るらしい。
が、正攻法ではないらしい。
ので、typeオプションで指定したくない場合は、
↓これ
http://d.hatena.ne.jp/gfx/20100610/1276159931
mark_raw を使う
例
[% htmlhaitteru | mark_raw %]
TTLではそんなことなかったのに。。
直すのか。
超メンドクサイ。。。
http://search.cpan.org/~gfuji/Text-Xslate-1.5012/lib/Text/Xslate/Syntax/TTerse.pm
↓こちらも参考になる模様
http://www.alink.co.jp/tech/blog/2010/09/01/perl-sledge%E3%81%A7textxslate%E3%82%92%E4%BD%BF%E3%81%86/
テンプレートに渡した値が、自動でエスケープされてて
オプションないのかって探したとき。
↓
http://d.hatena.ne.jp/gfx/20100822/1282469200
typeオプションでtextを指定すると出来るらしい。
が、正攻法ではないらしい。
ので、typeオプションで指定したくない場合は、
↓これ
http://d.hatena.ne.jp/gfx/20100610/1276159931
mark_raw を使う
例
[% htmlhaitteru | mark_raw %]
TTLではそんなことなかったのに。。
直すのか。
超メンドクサイ。。。
2012年04月13日
Text::Ngram::MySQL::FullText 文字化けする
http://g-chan.dip.jp/square/archives/2010/03/lamp_vol4.html
これと全く同じ現象が起きる。
どうやら、半角文字が入っていると
こういう現象が起きるっぽい。
ので、全角に変換してから、DBIでupdateする。
$searchText= Unicode::Japanese->new($contents)->h2z->get;
my $p = Text::Ngram::MySQL::FullText->new();
my $searchText = $p->to_fulltext( $searchText );
my $dbh = $schema->storage->dbh;
my $sth = $dbh->prepare(
"update tempTable" .
" set searchText = ? " .
" where id = ? ;"
);
$sth->execute($searchText , $id);
で文字化けをしなくなった。
DBIXでも問題ないです。
SQLは文字化けせずに投げられていたので、
おそらくDBIX側のバクかなぁ。
半角はやっかいです(´Д`) =3
これと全く同じ現象が起きる。
どうやら、半角文字が入っていると
こういう現象が起きるっぽい。
ので、全角に変換してから、DBIでupdateする。
$searchText= Unicode::Japanese->new($contents)->h2z->get;
my $p = Text::Ngram::MySQL::FullText->new();
my $searchText = $p->to_fulltext( $searchText );
my $dbh = $schema->storage->dbh;
my $sth = $dbh->prepare(
"update tempTable" .
" set searchText = ? " .
" where id = ? ;"
);
$sth->execute($searchText , $id);
で文字化けをしなくなった。
DBIXでも問題ないです。
SQLは文字化けせずに投げられていたので、
おそらくDBIX側のバクかなぁ。
半角はやっかいです(´Д`) =3
2012年03月12日
2012年02月17日
年齢計算
生年月日から年齢を計算する簡単な計算式
で
my ($year,$mon, $day) = (localtime(time))[5,4,3];
my $now = sprintf( "%04d%02d%02d", $year+1900, $mon+1, $day );
my $birth = sprintf( "%04d%02d%02d", $byear, $bmon, $bday );
print int( ($now - $birth) / 10000 );
と、簡単に計算できてしまうが
これは法律違反らしい↓
「生年月日から年齢を計算する簡単な計算式」は使えるとは限らない
単純に、法律上では誕生日の前日を、誕生日とするってことを言っているようだけれども
たぶん、日時に関する法律らへんで、こんなんなってるんじゃないかなー。
時間あったら探そっと。
2012年01月07日
2011年12月02日
perlは勝手に型変換
http://d.hatena.ne.jp/midori_kasugano/20090616/1245139122
慣れれば問題ないけれど
他の言語やってからperlを覚えるとき、少しネックになる。
my $count = @list;
とか。
他の言語だと、型変換関数とか、配列の要素数を得る関数とかを使う。
my int $count = count(@list);
みたいな。
タイプする手間減るから、キーボードでガリガリ書く人には便利かも。
perlってマウス操作がなかった時代に生まれた言語かな。
続きを読む
慣れれば問題ないけれど
他の言語やってからperlを覚えるとき、少しネックになる。
my $count = @list;
とか。
他の言語だと、型変換関数とか、配列の要素数を得る関数とかを使う。
my int $count = count(@list);
みたいな。
タイプする手間減るから、キーボードでガリガリ書く人には便利かも。
perlってマウス操作がなかった時代に生まれた言語かな。
続きを読む
2011年11月28日
mod_perlでIPアドレス取得
sub handler {
my $r = shift;
my $ip = $r->connection->remote_ip;
}
取れないし、サンプルソースないし、
英語のマニュアルしかないし、苦労した。
my $r = shift;
my $ip = $r->connection->remote_ip;
}
取れないし、サンプルソースないし、
英語のマニュアルしかないし、苦労した。
2011年09月13日
2011年09月08日
絵文字関係
対応表にどうぞ
http://www.unicode.org/~scherer/emoji4unicode/snapshot/full.html
Perl 5.8.x で shiftjis 、CP932、MacJapanese の違い
http://hardsoft.at.webry.info/200802/article_1.html
Encode::JP::Mobile
http://search.cpan.org/~coderepos/Encode-JP-Mobile-0.27/lib/Encode/JP/Mobile/Cookbook.pod
絵文字コード一覧表
http://code.cside.com/i-mode/emojimode/
http://www.unicode.org/~scherer/emoji4unicode/snapshot/full.html
Perl 5.8.x で shiftjis 、CP932、MacJapanese の違い
http://hardsoft.at.webry.info/200802/article_1.html
Encode::JP::Mobile
http://search.cpan.org/~coderepos/Encode-JP-Mobile-0.27/lib/Encode/JP/Mobile/Cookbook.pod
絵文字コード一覧表
http://code.cside.com/i-mode/emojimode/
2011年09月06日
Apache2::Const対応表
Apache2::Const - Perl Interface for Apache Constants
http://perl.apache.org/docs/2.0/api/Apache2/Const.html
エラーコードと、Apache2::Constの対応表、じゃばだけど。
http://java.sun.com/j2se/1.3/ja/docs/ja/api/java/net/HttpURLConnection.html
眠い。
http://perl.apache.org/docs/2.0/api/Apache2/Const.html
エラーコードと、Apache2::Constの対応表、じゃばだけど。
http://java.sun.com/j2se/1.3/ja/docs/ja/api/java/net/HttpURLConnection.html
眠い。
PerlResponseHandlerで$rに渡されるオブジェクト
日本語サイト少ない。
これ、らしい。っぽい。
http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html
クエリ文字列取り出したい。
my $args = $r->args();
my(@pairs) = split(/[&;]/,$args);
my($param,$value,%query);
foreach (@pairs) {
($param,$value) = split('=',$_,2);
next unless defined $param;
$value = '' unless defined $value;
$query{$param} = $value;
#$r-> print("$param:$value
");
}
これで、%queryに入る。
これ、らしい。っぽい。
http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html
use Apache2::RequestUtil ();
# add httpd config dynamically
$r->add_config(['require valid-user']);
# dump the request object as a string
print $r->as_string();
# default content_type
$content_type = $r->default_type();
# get PerlSetVar/PerlAddVar values
@values = $r->dir_config->get($key);
# get server docroot
$docroot = $r->document_root();
# set server docroot
$r->document_root($new_root);
# what are the registered perl handlers for a given phase
my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };
# push a new handler for a given phase
$r->push_handlers(PerlCleanupHandler => \&handler);
# set handlers for a given phase (resetting previous values)
$r->set_handlers(PerlCleanupHandler => []);
# what's the request body limit
$limit = $r->get_limit_req_body();
# server and port names
$server = $r->get_server_name();
$port = $r->get_server_port();
# what string Apache is going to send for a given status code
$status_line = Apache2::RequestUtil::get_status_line(404);
# are we in the main request?
$is_initial = $r->is_initial_req();
# directory level PerlOptions flags lookup
$r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');
# currentvalue
$location = $r->location();
# merge acontainer in a request object
$r->location_merge($location);
# create a new Apache2::RequestRec object
$r = Apache2::RequestRec->new($c);
# tell the client not to cache the response
$r->no_cache($boolean);
# share perl objects by reference like $r->notes
$r->pnotes($key => [$obj1, $obj2]);
# get HTML signature
$sig = $r->psignature($prefix);
# get the global request object (requires PerlOptions +GlobalRequest)
$r = Apache2::RequestUtil->request;
# insert auth credentials into the request as if the client did that
$r->set_basic_credentials($username, $password);
# slurp the contents of $r->filename
my $content = ${ $r->slurp_filename() };
# terminate the current child after this request
$r->child_terminate();
クエリ文字列取り出したい。
my $args = $r->args();
my(@pairs) = split(/[&;]/,$args);
my($param,$value,%query);
foreach (@pairs) {
($param,$value) = split('=',$_,2);
next unless defined $param;
$value = '' unless defined $value;
$query{$param} = $value;
#$r-> print("$param:$value
");
}
これで、%queryに入る。
2011年09月05日
XML::RSSのインストール
perlモジュールのinstallにcpanmを使う
http://www.omakase.org/perl/cpanm.html
cpanm Module名
で依存ファイルもインストールできる。
最新版でインストされるのかな。
今回は
cpanm XML::RSS
をインストールしました。
つまずいた。
cat /root/.cpanm/build.log
を見ると、膨大なエラーが出てる。
その中に、
Expat.xs:12:19: error: expat.h: No such file or directory
とある。
ネットで調べると、expat-develが必要らしい。
インストールする。
yum -y install expat-devel.i386
で、もう一回
cpanm XML::RSS
できた!
http://www.omakase.org/perl/cpanm.html
cpanm Module名
で依存ファイルもインストールできる。
最新版でインストされるのかな。
今回は
cpanm XML::RSS
をインストールしました。
つまずいた。
cat /root/.cpanm/build.log
を見ると、膨大なエラーが出てる。
その中に、
Expat.xs:12:19: error: expat.h: No such file or directory
とある。
ネットで調べると、expat-develが必要らしい。
インストールする。
yum -y install expat-devel.i386
で、もう一回
cpanm XML::RSS
できた!
CPANライブラリがインストールされてるか確認する方法
CPAN(Comprehensive Perl Archive Network)の
インストール済みモジュールの確認方法。
http://www.multiburst.net/project-multiburst/archives/2006/01/06/2348.php
できた!
インストール済みモジュールの確認方法。
http://www.multiburst.net/project-multiburst/archives/2006/01/06/2348.php
find `perl -e 'print "@INC"'` -name '*.pm' -print
これだと大量に出てしまうので、決め打ちならば、
find `perl -e 'print "@INC"'` -name 'Msql.pm' -print
これでインストールされているか確認できます。
できた!
2011年09月03日
mod_perlとmod_perl2で出来ることの違い
mod_perl温故知新 〜Perl CGIの高速化からメールサーバまで〜
http://www.slideshare.net/xtetsuji/mod-perl-hokkaidopm5
ここいい。
mod_perl2で作ることにします。
WEB開発1年ちょっと。
phpとperlのみでサーバー系の知識がないです。
普通さわれるものなのかな。
http://www.slideshare.net/xtetsuji/mod-perl-hokkaidopm5
ここいい。
mod_perl2で作ることにします。
WEB開発1年ちょっと。
phpとperlのみでサーバー系の知識がないです。
普通さわれるものなのかな。
2011年09月02日
2011年08月29日
2011年08月23日
http://howtobeahacker.seesaa.net/article/124016339.html
qq/string2/;
"string2";と同じで、ダブルクォートで囲んだ状態となります。
ダブルクォートなので、内部で変数も展開します。
[% mgs | html %]
[% mgs | html %]
| はフィルターらしい。
http://www.hakoniwa.net/tt/
ところで、「|」←これは何て読む?
|
http://www1.odn.ne.jp/haru/data-list/mark.html
| はフィルターらしい。
http://www.hakoniwa.net/tt/
「html」フィルターは < や > や & 文字を、HTMLタグや参照マークと見なされないようにエスケープします。
ところで、「|」←これは何て読む?
|
http://www1.odn.ne.jp/haru/data-list/mark.html
パイプ、パイプライン
vertical bar
2011年08月19日
BEGIN と END
http://www.geocities.jp/ky_webid/perl5/039.html
BEGINブロックは、他のコードよりも先にコンパイル・実行される特殊なブロックです。BEGINブロックの内部は、通常の Perl の文法が普通に使用できます。単に、どこよりも早くコンパイル・実行されるというだけのことです。
2011年08月18日
Data::Dumperについて
use Data::Dumper;
print Dumper(変数);
で、変数の中身が表示される。
他にも使い方いろいろある。
後日追記。
print Dumper(変数);
で、変数の中身が表示される。
他にも使い方いろいろある。
後日追記。
2011年08月04日
perl 演算子 ||=
||= 左辺値の値が FALSE であれば右辺値を代入
$x = 0;
$x ||= 2;
結果
2
コピペなんだけどいいのかな。
一応、リンクを。
http://www.rfs.jp/sb/perl/02/03.html
$x = 0;
$x ||= 2;
結果
2
コピペなんだけどいいのかな。
一応、リンクを。
http://www.rfs.jp/sb/perl/02/03.html
2011年07月06日
DBixとSQLのメモとperlの勉強方法とか
Catalyst + Lighttpd + FastCGI + DBIC + Schema::Loader に関する備忘録
http://www.drk7.jp/MT/archives/001202.html
「一番デキる人」に安住しない――ルー語変換・冨田尚樹さんの“学び力”
http://bizmakoto.jp/bizid/articles/0801/25/news081.html
この冨田尚樹さんのPerl勉強方法
Elementary, ... CPANの漁りかた
http://e8y.net/blog/2006/05/05/p117.html
いつか参考にしよう。
知らなきゃ絶対損するPCマル秘ワザ
http://daredemopc.blog51.fc2.com/blog-entry-149.html
豆知識的な?
http://www.drk7.jp/MT/archives/001202.html
「一番デキる人」に安住しない――ルー語変換・冨田尚樹さんの“学び力”
http://bizmakoto.jp/bizid/articles/0801/25/news081.html
この冨田尚樹さんのPerl勉強方法
Elementary, ... CPANの漁りかた
http://e8y.net/blog/2006/05/05/p117.html
いつか参考にしよう。
知らなきゃ絶対損するPCマル秘ワザ
http://daredemopc.blog51.fc2.com/blog-entry-149.html
豆知識的な?
perl開発環境構築 windows
体系だった情報にしたいとこですが、時間ないから後で。
理想こんなんがいい。
vim使ってみる。
http://www.atmarkit.co.jp/flinux/rensai/vim01/01b.html
インストールしてみただけ。
次、どうやってサーバーに接続するんだろう。。
そんな機能ないのか?
そうなのか。
http://sohda.net/cygwin/setenv.html
http://e8y.net/blog/2006/10/08/p134.html
http://ja.poderosa.org/present/about_poderosa.html
http://www.kaoriya.net/software/vim/about
理想こんなんがいい。
vim使ってみる。
http://www.atmarkit.co.jp/flinux/rensai/vim01/01b.html
インストールしてみただけ。
次、どうやってサーバーに接続するんだろう。。
そんな機能ないのか?
そうなのか。
http://sohda.net/cygwin/setenv.html
http://e8y.net/blog/2006/10/08/p134.html
http://ja.poderosa.org/present/about_poderosa.html
http://www.kaoriya.net/software/vim/about