perl

syntasticでperlのsyntaxcheckが動かなくなった件

RTFC 3.4.0 Syntax checker changes: Disable the perl checker by default, for security reasons (lcd047) https://github.com/scrooloose/syntastic/wiki/Changelog https://github.com/scrooloose/syntastic/wiki/Perl%3A---perl#security let g:syntast…

pit

アカウント情報を管理するコマンド pit - 冬通りに消え行く制服ガールは✖夢物語にリアルを求めない。 - subtech ruby pit | RubyGems.org | your community gem host require 'rubygems' require 'pit' config = Pit.get('example.com', :require => { 'user…

CPAN::Mini

% minicpan -r ftp://ftp.dti.ad.jp/pub/lang/CPAN/ -l ~/minicpan半日くらいかかった... % sudo /usr/bin/cpan cpan> o conf prerequisites_policy follow cpan> o conf urllist unshift file:///Users/oppara/minicpan cpan> o conf cpan> o conf commit c…

新しもの好きのダウンロード RSS

車輪? Hatena::Rss http://r.hatena.ne.jp/oppara/ Firefox rss.cgi #!/path/to/perl use strict; use warnings; use lib( './lib' ); use Encode; use CGI::Carp qw( fatalsToBrowser ); use Data::Dumper; use XML::RSS; use WWW::Atarashimonozuki::Scra…

Time::Piece->strptime()

時には、setlocaleしとかないと怒られることもある Error parsing time at /path/to/Time/Piece.pm line 470. #!/path/to/perl use Time::Piece; use POSIX qw( strftime locale_h); setlocale( LC_TIME, 'C' ); my $date = 'Mon Dec 17 22:19:36 2007 GMT';…

タイムゾーンゲット

http://www.misao.gr.jp/~koshian/?20050819S1 #!/path/to/perl use POSIX qw( strftime ); ( my $z = strftime( '%z', localtime) ) =~ s/(\d\d)(\d\d)/$1:$2/; print strftime( '%Y-%m-%dT%H:%M:%S', localtime ), $z, "\n";

モジュールのインストール先

% perldoc -ml Hoge

よくわからんマシンにモジュールをインストール

適当なディレクトリにインストール perl Makefile.PL PREFIX=/path/to/want localeエラー perl -vとかすると以下のエラーが出る perl: warning: Please check that your locale settings: LANGUAGE = "ja_JP.SJIS", LC_ALL = "ja_JP", LANG = "ja_JP" are su…

SVN::Web

SVN-Web-0.53 - Subversion repository web frontend - metacpan.org インストール 素のperlは面倒そうだったので、portのperlを使用。 $ cd ~/src $ curl -O http://search.cpan.org/CPAN/authors/id/A/AS/ASH/SVN-Placeholder-0.00001.tar.gz $ tar xzvf S…

Module::Starter

Module::Starter $ module-starter --module=Hoge::Moge::Hage Perl Best Practices Module::Starter::PBP $ perl -MModule::Starter::PBP=setup$ find ~/.module-starter -type f /Users/oppara/.module-starter/PBP/Build.PL /Users/oppara/.module-starte…

XML::Parserのインストール

portでexpatを入れてるので、cpanだとこける。 $ perl Makefile.PL EXPATLIBPATH=/opt/local/lib EXPATINCPATH=/opt/local/include

LWP::SimpleでHEAD

use LWP::Simple; my $url = 'http://www.example.com/'; my ( $content_type, $document_length, $modified_time, $expires, $server ) = head( $url ); # or my $head = head( $url ); print $head->{_headers}->{etag}; print $head->{_headers}->{'last-…

配列のシャッフル

$ perl -e 'use List::Util qw(shuffle);$,=",";print shuffle( 0..10 ),"?n";' 5,2,7,6,8,4,3,9,1,10,0, -Mでサブルーチンのエクスポート方法がわからん。

CPANの再設定を行う

cpan> o conf init

配列からハッシュ

my @array = qw/ foo, bar, baz /; my %hash = map { $_ => 1 } @array; my @keys = qw/ foo bar baz /; my @values = qw/ hoge moge hage /; my %hash = (); @hash{@keys} = @values;

ソースコード整形

The Perltidy Home Page .perltidyrc(Best Practices & ねずみ本) -l=78 # Max line witdh is 78 cols -i=4 # Indent level is 4 cols -ci=4 # Continuation indent is 4 cols -st # Output to STDOUT -se # Errors to STDERR -vt=2 # Maximal vertical tigh…

現在時刻

use POSIX( 'strftime' ); use constant LF => "\n"; $ENV{TZ} = 'JST-9'; print strftime( '%z', localtime ), LF; # タイムゾーン print strftime( '%Y-%m-%d %H:%M:%S', localtime ), LF;

ヒアドキュメント

最初のEOFをシングルクォートで挟むと変数は展開されない。 shell cat <

HTMLエンティティのエンコーディング

perl -Mencoding=utf8 -MHTML::Entities -ple '$_=encode_entities($_, "<>&")' ファイル

SpeedyCGI

http://www.daemoninc.com/SpeedyCGI/ http://sourceforge.net/projects/speedycgi/ CPANの奴はmakeでこける。 make[1]: *** [speedy_backend] Error 1 make: *** [subdirs] Error 2 cvs版を落とす $ cvs -d:pserver:anonymous@speedycgi.cvs.sourceforge.ne…

置換まとめ

perl -p -i.bak -e 's/foo/bar/g' *.hoge非道版 perl -p -e 's/foo/bar/g' *.hoge with grep カレントディレクリ以下の'hoge'という文字列を含むファイルを検索し そのファイル内の'foo'を、すべて'bar'に変換する。 grep -lr 'hoge' . | xargs perl -p -i.b…

ダイアリーのバックアップ

use strict; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; my $mode = 'export'; my $username = 'oppara'; my $password = 'pass'; my $cookie_file = '/path/to/cookie.txt'; my $bak_file = '/path/to/hatena.bak'; my $export_ur…

丸呑み

{ local( $/, *FH ) ; open( FH, $file ) or die "$!\n" $text = <FH>; }open my $in, '<', $file or die "$!\n" my $text = do { local $/; <$in> };</fh>

DBD::mysqlのインストール

DBD::mysql 3.0002_4はmakeできなかった。 ので、DBD-mysql-2.9005をソースからインストール $ perl Makefile.PL --testdb=test --testuser=user \ --testpassword=pass --mysql_config=/usr/local/mysql/bin/mysql_config $ make $ make test $ sudo make …

DBD::Pgのインストール

cpan> install DBD::Pg

cpan

使い方 $ sudo perl -MCPAN -e shellモジュールの一覧 perl -MCPAN -e 'CPAN::Shell->r'古くなっているモジュールの一括アップデート sudo perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'