memo.xight.org

Home > Changelogメモ > Perl > 1ページ目 (全6ページ)
ChangeLog 最新ページ / カテゴリ最新ページ / 1 2 3 4 5 6 次ページ / 1ページ目 (全6ページ)
2008-09 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

2008-05-13 Tue

Unicode の16進数の数値文字参照を正規表現などで元に戻す

- Summary
� のような数値文字参照から元の文字に戻す方法.

- Encodeを使用する方法

#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use utf8;
binmode STDOUT, ":utf8";
my $a = "情報時代";
$a =~ s/&#x([0-9A-F]{4});/decode('UCS2', pack('H*', $1))/ge;
print "$a\n";


- HTML::Entitiesを使用する方法
my $a = "情報時代";
use HTML::Entities;
print HTML::Entities::decode($a), "\n";


- 正規表現を使用する方法
my $a = "情報時代";
$a =~ s/&#x([0-9A-F]{4});/chr(hex($1))/ge;
print "$a\n";


- Reference
たつをのChangeLog - 2008-05-10 - Unicode の16進数の実体参照を正規表現などで元に戻す
http://chalow.net/2008-05-10-3.html

404 Blog Not Found - 2008-05-11 - perl - 文字参照を(en|de)codeする
http://blog.livedoor.jp/dankogai/archives/51048882.html

HTML::Entities

カテゴリ: [Unicode][Perl]

2008-02-12 Tue

YAPC::Asia 2008

- Reference
Welcome: YAPC::Asia 2008 - May 15-16th in Tokyo, JAPAN
http://conferences.yapcasia.org/ya2008/

カテゴリ: [Perl]

2007-02-15 Thu

Perlで日付・時間を操作 - DateTime モジュールの使い方

- Reference
Perlで日付・時間を操作 - DateTime モジュールの使い方 (iandeth.)
http://iandeth.dyndns.org/mt/ian/archives/000619.html

カテゴリ: [Perl]

2007-02-13 Tue

スクリプト言語用のデバッガの使い方

- Reference
いやなブログ - スクリプト言語用のデバッガの使い方 - Ruby, Python, Perl
http://0xcc.net/blog/archives/000162.html

- via
www.textfile.org - スクリプト言語用のデバッガの使い方 - Ruby, Python, Perl
http://d.hatena.ne.jp/textfile/20070212/dbg

カテゴリ: [Ruby][Python][Perl]

2006-11-30 Thu

coLinux 上の Emacs の kill-ring の内容をWindowsのクリップボードと同期する

- Reference
naoyaのはてなダイアリー - coLinux 上の Emacs の kill-ring の内容をWindowsのクリップボードと同期する by Perl
http://d.hatena.ne.jp/naoya/20061125/1164466544

odz buffer - coLinux で Emacs の kill-ring の内容をWindowsのクリップボードと同期する
http://d.hatena.ne.jp/odz/20061125/1164433815

odz buffer - coLinux で Emacs の kill-ring の内容をWindowsのクリップボードと同期する #2
http://d.hatena.ne.jp/odz/20061125/1164437987

カテゴリ: [Perl][Python][Emacs]

2006-11-30 Thu

String::Diff - 行内差分取得モジュール

- Summary
Perlの行内差分取得モジュール.

- 文字列同士の差分を作って変更無い場所,変更が合った場所で配列を分けて作成.

my $diff = String::Diff::diff_fully('this is Perl', 'this is Ruby');
for my $line (@{ $diff->[0] }) {
    print "$line->[0]: '$line->[1]'\n";
}
# u: 'this is '
# -: 'Perl'
 
for my $line (@{ $diff->[1] }) {
    print "$line->[0]: '$line->[1]'\n";
}
# u: 'this is '
# +: 'Ruby'


- 差分の合った部分にマークを付ける.
my $diff = String::Diff::diff('this is Perl', 'this is Ruby');
 
print "$diff->[0]\n";# this is [Perl]
print "$diff->[1]\n";# this is {Ruby}
 
my $diff = String::Diff::diff('this is Perl', 'this is Ruby',{
    remove_open => '<del>',
    remove_close => '</del>',
    append_open => '<ins>',
    append_close => '</ins>',
});
 
print "$diff->[0]\n";# this is <del>Perl</del>
print "$diff->[1]\n";# this is <ins>Ruby</ins>


- 差分同士の結果をマージして一つの文字列にする.
my $diff = String::Diff::diff_merge('this is Perl', 'this is Ruby'{
    remove_open => '<del>',
    remove_close => '</del>',
    append_open => '<ins>',
    append_close => '</ins>',
});
int "$diff\n";# this is <del>Perl</del><ins>Ruby</ins>


- 正規表現のパターンにする.
my $diff = String::Diff::diff_regexp('this is Perl', 'this is Ruby');
print "$diff\n";# this\ is\ (?:Perl|Ruby)


- 利用例
Hatena::Wiki - Kwiki mutual diffs
http://hatenawiki.blogdb.jp/?action=diff&page_name=HomePage&revision_id=2&current_revision_id=3

- Reference
YappoLogs: String::Diff - 行内差分取得モジュール
http://blog.yappo.jp/yappo/archives/000479.html

String::Diff

カテゴリ: [Perl]

2006-11-25 Sat

Net::SSL::ExpireDate + Test::Base で証明書の期限切れをチェック

- Summary
Net::SSL::ExpireDateTest::Baseを用いて,SSL証明書の期限切れをチェック.

#!/usr/bin/env perl
# -*- mode: cperl; -*-
use Test::Base;
use Net::SSL::ExpireDate;
use Regexp::Common qw(net);
 
my $Check_Duration;
# $Check_Duration = '15 years';
 
plan tests => 1 * blocks;
 
run {
    my $block = shift;
    my $ed = Net::SSL::ExpireDate->new( build_arg($block->name) );
    is($ed->is_expired($Check_Duration) && $ed->expire_date->iso8601,
        undef,
        $block->name);
};
 
sub build_arg {
    my ($v) = @_;
    if ($v =~ m{^(file)://(.+)}) {
        return $1 => $2;
    } elsif ($v =~ m{^(https)://([^/]+)}) {
        return $1 => $2;
    } elsif ($v =~ m{^$RE{net}{domain}{-nospace}{-keep}$}) {
        return 'https' => $1;
    } elsif (-r $v) {
        return 'file' => $v;
    } else {
        croak "$v: assume file. but cannot read.";
    }
}
 
__END__
=== rt.cpan.org
=== www.google.com


- Reference
(ひ)メモ - Net::SSL::ExpireDate + Test::Base で証明書の期限切れをチェック
http://d.hatena.ne.jp/hirose31/20061121/1164042331

- via
オレンジニュース - 2006-11-21
http://secure.ddo.jp/~kaku/tdiary/20061121.html#p10

カテゴリ: [Perl]

2006-11-21 Tue

Lingua::JA::Summarize::Extract を利用した日本語文章の要約

- Summary

use strict;
use warnings;
use utf8;
use Lingua::JA::Summarize::Extract;
 
my $extracter = Lingua::JA::Summarize::Extract->new;
my $text = "日本語の文章を沢山書きます";
my $result = $extracter->extract($text);
my $summary = $result->as_string;
 
utf8::encode($summary);
print $summary; #サマリーが出てくる.


- Reference
Lingua::JA::Summarize::Extract

YappoLogs - 2006-11-13 - Lingua::JA::Summarize::Extract - 日本語文章のサマリ抽出
http://blog.yappo.jp/yappo/archives/000473.html

無駄に長いテキストを要約する
http://stone.dialog.jp/archives/extract/index.cgi

Voice of Stone #1469 無駄に長い文章を要約するツール
http://stone.dialog.jp/voice/view/1469

カテゴリ: [Perl]

2006-11-18 Sat

日本の総理大臣の演説をタグクラウド化

- Summary
1. HTML::TreeBuilder で as_text
2. Text::MeCab で形態素解析
3. 名詞の頻度データを YAML に変換
4. HTML::TagCloud でタグクラウド化

- Reference
Japanese Prime Minister Speeches Tag Cloud - 日本の首相演説のタグクラウド
http://blog.bulknews.net/PMTagCloud/

日本の総理大臣の演説をタグクラウド化: blog.bulknews.net
http://blog.bulknews.net/mt/archives/002078.html

HTML::TreeBuilder
Text::MeCab
YAML
HTML::TagCloud

カテゴリ: [Perl]

2006-11-18 Sat

UTF-8 で半角カナを判定

- Summary
。と゜は半角で

print if /[。-゜]/;


- Reference
[を] UTF-8 で半角カナを判定
http://chalow.net/2006-11-09-3.html

カテゴリ: [Perl]

2006-09-19 Tue

Dumpvalue で Perlのデバッグ

- Summary
Data::Dumperを卒業.

- Sample

use Dumpvalue;
 
my $d = Dumpvalue->new();
 
# dumpValue
$d->dumpValue($target);
$d->dumpValue(\@target);
 
# dumpValues
$d->dumpValues($target1,$target2);


- Reference
Dumpvalue
Data::Dumper

[を] Perl でのデバグ用のダンプ
http://chalow.net/2006-09-15-4.html

カテゴリ: [Perl]

2006-09-15 Fri

TripletaiL - Linux+Apache+MySQL+Perl環境で動作する日本発オープンソースフレームワーク

- Summary
TripletaiL とは,Linux+Apache+MySQL+Perl環境で
日本語のウェブアプリケーションを構築するためのオープンソースフレームワーク.

- Reference
TL - Perlフレームワーク
http://tripletail.jp/

カテゴリ: [Perl]

2006-09-15 Fri

Term::TtyRec - Perlでttyrec

- Summary
Perlからttyrecを扱うモジュール.

- SYNOPSIS

use Term::TtyRec::Player;
use FileHandle;
 
# $handle is any IO::* object
my $handle = FileHandle->new('file.tty');
my $player = Term::TtyRec::Player->new($handle);
 
# options can be set as hashref
my $player = Term::TtyRec::Player->new($handle, {
    speed => 1, nowait => undef,
});


- Reference
Term-TtyRec

GraphicWizardsLair - 2006-09-12 - コンソールをネット越しにライブで見せたいのであればscreen -xじゃなくてttyrecを使った方が簡単
http://www.otsune.com/diary/2006/09/12/1.html#200609121

ttyrec: ttyレコーダー
http://0xcc.net/ttyrec/

- via
www.textfile.org - 2006-09-13
http://d.hatena.ne.jp/textfile/20060913/tty

カテゴリ: [Perl]

2006-09-13 Wed

ローカルのPerlモジュールを使用する

- Summary

use lib 'path/to/lib';
use Foo;


- Sample
path/to/lib 以下にモジュールを配置.
Text::Iconvを利用する場合は,スクリプトから見て
path/to/lib/Text/Iconv.pm
に配置.

use lib 'path/to/lib';
use Text::Iconv;


- Reference
hail2u.net - Weblog - 2004-05-06 - push @INCとuse lib
http://hail2u.net/blog/coding/push_at_inc_and_use_lib.html

カテゴリ: [Perl]

2006-09-12 Tue

UTF-8で書かれたWebページから namazu で検索

- Summary
あるページからnamazu.cgiに検索文字列を送信する際,
遷移元のページがUTF-8の場合,検索が行なえない.

namazu.cgiがEUC-JPでHTMLエンコードされた検索文字列のみ対応しているのに対し,
遷移元ページがUTF-8で記述されている場合,検索文字列もUTF-8でHTMLエンコードされるため.

1. namazu.cgi を namazu2.cgi にリネーム.
2. 文字コード変換フィルタを namazu.cgi として設置
3. namazu.cgi 中で namazu2.cgi へリダイレクト.

- Source

#!/usr/bin/perl
 
use CGI;
use Text::Iconv;
use CGI::Lite;
 
my $converter = Text::Iconv->new("UTF8", "EUC-JP");
my $cgi = new CGI;
my $new_query = q();
 
# パラメータが空の場合を考慮
if ($cgi->param('key')){
	$new_query = $converter->convert($cgi->param('key'));
}
 
$uencode = url_encode($new_query);
print "Location: http://example.com/path/to/namazu2.cgi?key="."$uencode\n\n";


- 補足
<form> タグの accept-charsetでも回避可能.
(Firefox1.5で動作を確認.Internet Explorer 6では動作せず.)
<form accept-charset="euc-jp">
</form>


- Reference
namazuでUTF8ファイルの検索
http://www.ksknet.net/linux/namazuutf8.html

CGI
CGI::Lite
Text::Iconv

カテゴリ: [Perl]

2006-09-07 Thu

Perl でデコメールの送信

- Summary
デコメールの送信方法.

- デコメールのパターン
1. HTMLのみ
2. HTML + 画像添付
3. HTML + インライン画像
4. デコメールテンプレート

- 1. HTMLのみのフォーマット
デコメール非対応の端末にはTEXTパートのみ送信される.
よって,TEXTパートを必ず付ける.

Content-Type:multipart/alternative
  Content-Type:text/plain
    メールの内容 (テキスト)
  Content-Type:text/html
    メールの内容 (HTML)


- 2. HTML + 画像添付

Content-Type: multipart/mixed
  Content-Type: multipart/alternative
    Content-Type:text/plain
      メールの内容 (テキスト)
    Content-Type:text/html
      メールの内容 (HTML)
  
  Content-Type:image/gif
  Content-Transfer-encoding:base64
    (base64で符号化されたgifファイル)


- 3. HTML + インライン画像

Content-Type:multipart/related
  Content-Type: multipart/alternative
    Content-Type:text/plain
      メールの内容 (テキスト)
    Content-Type:text/html
      メールの内容 (HTML)

  Content-Type:image/gif
  Content-Transfer-encoding:base64
  Content-ID:<sample>
    (base64で符号化されたgifファイル)


- 4. デコメールテンプレート
改行は CR + LF.
Content-Typeは application/x-decomail-template
Decomail-Template
MIME-Version:1.0
Content-Type:multipart/related
  Content-Type: text/html;charset=Shift_JIS
  Content-Transfer-Encoding:8bit
    (HTML本文)
    <img src="cid:sample">

  Content-Type:image/gif
  Content-Transfer-encoding:base64
  Content-ID:<sample>
    (base64で符号化されたgifファイル)


- Reference
CodeZine - Perlで作るモバイルサイトのコツ : 第2回 (デコメール)
http://codezine.jp/a/article.aspx?aid=550

CodeZine - Perlで作るモバイルサイトのコツ : 第2回 (デコメール)
http://codezine.jp/a/article.aspx?aid=550&p=2

MIME::Lite
Jcode

カテゴリ: [Perl][Mobile]

2006-08-26 Sat

mod_perl と mod_phpの比較

- Summary
互角.

- Reference
ITmedia エンタープライズ - 2006-08-25 - LAMP vs. LAMP─ mod_perlとmod_phpのパフォーマンス比較
http://www.itmedia.co.jp/enterprise/articles/0608/25/news053.html

NewsForge - 2006-07-18 - LAMP vs. LAMP
http://programming.newsforge.com/article.pl?sid=06/07/18/1934200

カテゴリ: [Perl][PHP][Apache]

2006-08-02 Wed

Perlでモバイルサイト構築

- Summary
1. User-Agentで端末判別
HTTP::MobileAgentを利用

use HTTP::MobileAgent;
 
my $agent = HTTP::MobileAgent->new;
 
if ($agent->is_docomo){
	    # iモード
} elsif ($agent->is_ezweb){
	    # EZweb
} elsif ($agent->is_vodafone){
	    # Vodafone
}


2. 端末に応じてHTML出力
Template-ToolkitHTTP::MobileAgentを利用
#!/usr/bin/perl
 
use CGI;
use Template;
use HTTP::MobileAgent;
 
my $q = CGI->new;
my $agent = HTTP::MobileAgent->new;
my $tt = Template->new({ABSOLUTE => 1});
 
my $output;
 
# sample.htmlのagentパラメータへ
# HTTP::MobileAgentのインスタンスをセットする
$tt->process('/path/to/sample.html', {agent => $agent}, \$output) or die $Template::ERROR;
 
print $q->header(-charset=>'Shift_JIS');
print $output;
 
exit;

<html>
<body>
[% IF agent.is_docomo %]
iモード
[% ELSIF agent.is_ezweb %]
EZweb
[% ELSIF agent.is_vodafone %]
Vodafone Live!
[% ELSE %]
Non Mobile...
[% END %]
</body>
</html>


3. メールアドレスのキャリア判別
Mail::Address::MobileJp
use Mail::Address::MobileJp;
 
if (is_imode($email)){
	# @docomo.ne.jp
}elsif (is_ezweb($email)){
	# @ezweb.ne.jp or @*.ezweb.ne.jp
}elsif (is_vodafone($email)){
	# @jp-*.ne.jp or @*.vodafone.ne.jp
	# (*にはd,h,t,c,k,r,n,s,qのみが適用となる)
}


4. 絵文字対応
HTML::Entities::ImodePictogram
3キャリア対応の絵文字削除
use CGI;
use HTML::Entities::ImodePictogram;
 
my $q = CGI->new;
 
my $text = $q->param('text');
 
# EZwebの絵文字も削除対象にする
$HTML::Entities::ImodePictogram::ExtPictorgram_re .= '|[\xF3\xF4\xF6\xF7][\x40-\x7E\x80-\xFC]';
 
# iモード、EZwebの絵文字を削除
$text = remove_pictogram($text);
 
# Vodafoneの絵文字を削除
$text =~ s/\x1B\$(.+?)\x0F//g;


- Reference
CodeZine - Perlで作るモバイルサイトのコツ:第1回
http://codezine.jp/a/article.aspx?aid=496

HTTP::MobileAgent
Template-Toolkit
Mail::Address::MobileJp
HTML::Entities::ImodePictogram

カテゴリ: [Perl][Mobile]

2006-08-01 Tue

mysqldump2email - MySQLのダンプファイルをzipアーカイブしてメール送信

- Summary
以下のモジュールが必要
MIME::Lite
DateTime
YAML

- Usage

% mysqldump2email --conf /path/to/config.yaml


- config.yaml sample

mysqldump:
  command: /usr/bin/mysqldump
  username: your-mysql-username
  password: your-mysql-password
  #host: localhost
 
zip:
  command: /usr/bin/zip
  # if encryption needed
  #password: your-zip-password
 
mail:
  from: user@example.com
  to:   user@example.com
  route:
    via:  smtp
    host: localhost:25
  #route:
  #  via:  sendmail
 
gspace:
  enable: 0
  directory: /
 
tmpdir: /tmp
#time_zone: Asia/Tokyo


- Reference
Ogawa::Memoranda - 2006-07-24 - mysqldump2email公開
http://as-is.net/blog/archives/001149.html

- via
オレンジニュース - 2006-07-28
http://secure.ddo.jp/~kaku/tdiary/20060728.html#p04

カテゴリ: [MySQL][Perl]

2006-08-01 Tue

まるごとPerl! Vol.1

- Summary
Amazon -
- Reference
まるごとPerl! Vol.1

カテゴリ: [Perl][]
2008-09 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
最終更新時間: 2008-09-05 14:14

Color Reference

ChangeLogを検索
携帯電話からアクセス!

カテゴリ

最近の話題

リンク

過去ログ

Google

QR Code

Since
2002-11-28
Update
2008-09-05 14:14
Copyright © 2005 xight.org All Rights Reserved.