七行プログラミング (452レス)
上下前次1-新
169: nobodyさん [sage] 03/10/08 01:14 ID:??? AAS
 5.005_03 と 5.8.0 の両方でマジメにチェック & 縮め。 
  
 #!/usr/local/bin/perl 
 use CGI':all';sub e{my@e;for(0..63){@x=(@{[qw(+ - * /)]}[$_&3,$_>>2&3,$_>>4&3], 
 @n,param n);for$t(qw/(304)1(526) ((304)15)26 30(41(526)) 30((415)26) 
 (30(415))26/){$_=$t;s/(\d)/$x[$1]/g;10-eval or$r?push@e,$_.br:put("$n:$_\n"),$c 
 &&return}}@e}($r=$ENV{REMOTE_ADDR})?put(header,start_html(-title=>7410), 
 startform(0,script_name),p(scrolling_list(-values=>[0..9],name,n,size,10)x4, 
 submit),endform,p(e),end_html):do{$$_=1for"@ARGV"=~/\w/g;$n=$_,$h{"@{[sort@n= 
 /./g]}"}++&&$o||$z&&/0/||$d&&4>keys%{{map{$_,1}@n}}or e for'0019'..'9999'} 
170: 7blosxom [] 03/12/01 03:01 ID:i/vnv4B8(1/4) AAS
 #!/usr/bin/perl 
 use CGI':all';use File::Find;$n=param('n')||0;@i=split'/',path_info;shift@i;($y, 
 $m,$d)=grep{/^\d+$/}@i;$p=join'/',grep{/^\D+$/}@i;find sub{($f=$File::Find::name 
 )=~/\.txt$/and$e{$f}=-M},"./$p";put header,start_html;for((sort{$e{$a}<=>$e{$b}} 
 keys%e)[$n..$n+40]){($z,$x,$c)=(localtime(time-60*60*24*$e{$_}))[5,4,3];next if( 
 ($y&&$y!=$z+1900)or($m&&$m!=$x+1)or($d&&$d!=$c)or!-f);s/^\.\///;open(F,$_)&&{ 
 chomp($t=<F>),put(a({-href=>url."/$_"},h2 $t),<Fhr,"\n"),close F}}put end_html 
171: 7blosxom [] 03/12/01 03:13 ID:i/vnv4B8(2/4) AAS
 久しぶりに7行プログラミング。 
  
 PATH_INFOで指定できるのは、日付とカテゴリのみ。 
 月の指定は数字のみ可能。Decとかには未対応。 
 indexや他のFlavourは未実装。 
  
 リクエストの例 
 ./7blosxom.cgi 
 ./7blosxom.cgi/2003 
 ./7blosxom.cgi/2003/11 
 ./7blosxom.cgi/2003/11/30 
 ./7blosxom.cgi/2003/11/foo 
 ./7blosxom.cgi/2003/foo/bar 
 ./7blosxom.cgi/foo/hoge.txt 
  
 PAGING 機能。意味なくつけてみたけど、いらないよぉな気がする。(TODO remove) 
 ./7blosxom.cgi?n=10 
 ./7blosxom.cgi?n=10/foo/2000 
  
 リクエスト例。例外 
 ./7blosxom.cgi///// ... 何も指定しないのと同じ。 
 ./7blosxom.cgi/2003/11/30/1/ ... 4つめ以降の数字は無視される。 
 ./7blosxom.cgi/foo2/ ... 正規表現が手抜きな為、数字+文字の組合せは無視される。
172: nobodyさん [] 03/12/01 06:28 ID:i/vnv4B8(3/4) AAS
 訂正。HTML&&桁数間違えてた。 
  
 #!/usr/bin/perl 
 use CGI':all';use File::Find;@i=split'/',path_info;shift@i;($y,$m,$d)=grep/^\d+ 
 $/x,@i;$p=join'/',grep{/^\D+$/}@i;find sub{($f=$File::Find::name)=~/\.txt$/and$ 
 e{$f}=-M},"./$p";put header,start_html;for(sort{$e{$a}<=>$e{$b}}keys%e){($z,$x, 
 $c)=(localtime(time-86400*$e{$_}))[5,4,3];if(!(($y&&$y!=$z+1900)or($m&&$m!=$x+1 
 )or($d&&$d!=$c))&&-f&&open F,$_){s/^\.\///;chomp($t=<F>);put hr,h2 a({href,url. 
 "/$_"},$t),pre<F"\n";close F}}put end_html 
  
 - データ用のディレクトリをカレントディレクトリ以外に指定したい場合。 
   ln -s /home/your/data/path home とリンクを作り。 
   7blosxom.cgi/home とアクセスする。
173(1): 128 [] 03/12/01 18:34 ID:xLzdr2os(1) AAS
 それじゃ漏れも久々に投稿。 
 スレッド式掲示板です。 
 データ用ディレクトリ G が必要です。 
  
 ---------------------- 7thread.cgi ----------------------- 
 use CGI":all";charset"x-sjis";*i=*param;*e=*escapeHTML;chdir G;i B,$b,open F,"> 
 $b"if($b=e(i S))&&!-e$b;$b||=i(B);*x=*textfield;open F,"+<$b";[<F>];seekF,0,2;s 
 !外部リンク:.+$!a{href,$&},$&!emg,s/\n/br/eg,$n=e(i N)||'七氏',print F dt(++$.,':'. 
 b(a{i(M)&&(href,'mailto:'.e(i M))},$n),':'.localtime),dd($_.p),"\n"if$_=e(i T); 
 seek F,0,0;put header,start_html($b),h1($b),startform,(i B)?dl(<F>).a{href,'?'} 
 ,'一覧':ol(li[map{a{href,"?B=$_"},$_}sort{-A$a<=>-A$b}<*>]).hr.'スレ'.x(S),hidden 
 (B),br,submit,'名前',x(N),'MAIL',x(M),br,textarea(T,'',6,80,1),endform,end_html 
 ------------------------------------------------------
174(3): nobodyさん [] 03/12/01 20:35 ID:lEOu0k9S(1) AAS
 モジュールありだったらいくらでも短くできるのでは? 
175(5): nobodyさん [] 03/12/01 23:22 ID:i/vnv4B8(4/4) AAS
 #!/usr/bin/perl 
 #7blosxom.cgi 
 use CGI':all';use File::Find;($p,$y,$m,$d)=grep/^\D+$/,(@i=split'/',path_info), 
 grep/^\d+$/,@i;find sub{($f=$File::Find::name)=~/\.txt$/and $e{$f}=-M},"./$p"; 
 put header,start_html;for(sort{$e{$a}<=>$e{$b}}keys%e){($c,$x,$z)=(localtime( 
 time-86400*$e{$_}))[3..5];if(!($y&&$y!=$z+1900||$m&&$m!=$x+1||$d&&$d!=$c)&&-f&& 
 open F,$_){s/^\.\///;chomp($t=<F>);put h2 a({href=>url."/$_"},$t),pre<Fhr; 
 close F}}put end_html 
 __END__ 
  
 変更点 
 < shift@i はいらなかった。 
 < [5,4,3] をスライスに変更。 
 < 変数をまとめて宣言。 
  
 >174 
 そうだね。過去ログを読めばわかる通り、それは人によって意見がわかれる所。標準モジュールはokとか。 
 自分は、モジュールを使っても既存のリソースの有り合わせでおもしろいものが出来ればいいなと思ってる。 
 wikiもCPANのWiki::関連のモジュールを使えば制限内でも、もっと機能追加出来そうだし。 
 ただし、短くするためにわざわざモジュールを作る気はなし。
176: nobodyさん [sage] 03/12/02 14:16 ID:??? AAS
 >>175 
 h2タグの中にpreタグ(と本文)が入るのですが・・・
177(1): nobodyさん [sage] 03/12/02 18:25 ID:??? AAS
 >>175 
 Blosxom 知らんかったので和訳サイト読みながらゴニョゴニョ中。 
 動作確認用の txt ファイルセット用意してくれたら嬉しい。日付と 
 中身が違うファイルを沢山作るのは結構ダルい。;) 
178: nobodyさん [sage] 03/12/02 22:21 ID:??? AAS
 >>173 
 足したり引いたりしてみた。 
  
 use CGI":all";*i=*param;*x=*textfield;sub e{escapeHTML i(pop)}chdir G;-e($b=i(B 
 )||e S)or open F,">$b";open F,"+<$b";eval{flock F,2};[<F>];s!外部リンク:.+$!a{href, 
 $&},$&!eg,s/\n/br/eg,print F dt($.+1,':',b(a{href,'mailto:'.e M},e(N)||nobody), 
 ':'.localtime),dd($_),"\n"if$_=e T;seek F,0,0;put header,start_html($b), 
 startform,$b?h1($b).dl(<F>).hidden(B,$b).a{href,'?'},list:ol(li[map{a{href, 
 "?B=$_"},$_}sort{-M$a<=>-M$b}<*>]).thread.x(S),br,submit,NAME,x(N),MAIL,x(M),br 
 ,textarea(T,'',6,80,1),endform,end_html 
179: nobodyさん [sage] 03/12/02 23:32 ID:??? AAS
 >>177 
 #!/usr/bin/perl 
 @c=('a'..'z','A'..'F');$t=time;sub j{join'',@c[$_[0]..$_[0]+2]}for(0..23){open( 
 T,'>'.($f=j($_).'.txt'))||die$!;print T j($_),"\n",j($_+3),"\n",j($_+6);utime( 
 $t,$t,$f)||die$!;$t-=25000}opendir(D,'.')||die$!;@f=grep!/^\./,sort readdir D; 
 $t=(stat$f[0])[9]-32000000;for(@f){open(S,$_)||die$!;s/^(\w+)/++$i.uc$1/e;open( 
 D,">$_")||die$!;print D map uc,<S>;utime$t,$t,$_;$t-=50000} 
180(1): nobodyさん [sage] 03/12/03 02:02 ID:??? AAS
 5.005_03 と 5.8.2 で確認。元より長くなったけど…。 
  
 #!/usr/bin/perl 
 use CGI':all';use File::Find;/^\d+$/?$y?$m?($d||=$_):($m=$_-1):($y=$_-1900):/\. 
 txt$/x?($f||=$_):length&&($c.="/$_")for split'/',path_info;find sub{($D,$M,$Y)= 
 (localtime($t=(stat)[9]))[3..5];$e{$File::Find::name}=$t if!($y&&$y-$Y)&&!($m&& 
 $m-$M)&&!($d&&$d-$D)&&(!$f||/^$f$/)&&/\.txt$/},".$c";put header,start_html;for( 
 sort{$e{$b}<=>$e{$a}}keys%e){open F,$_;s|\.||;chomp($h=<F>);put h2(a{href,url. 
 $_},$h),pre<Fhr}put end_html 
  
 ・数字は年・月・日としてこの順に拾われ、4つ目以降は無視 
 ・数字のみのカテゴリ名は許されないが、含む事は可 
 ・カテゴリは出現順に階層化されているものとして処理する 
 ・".txt" が末尾に付くものはファイルとし、最初に現れたもののみ有効 
  
 例 
 ./7blosxom.cgi 
 ./7blosxom.cgi/2003 
 ./7blosxom.cgi/2003/11 
 ./7blosxom.cgi/2003/11/30 
 ./7blosxom.cgi/foo 
 ./7blosxom.cgi/hoge.txt 
 ./7blosxom.cgi/foo/hoge.txt 
 ./7blosxom.cgi/2003/foo/bar 
 ./7blosxom.cgi/2003/foo/11/bar/30/fuga.txt 
 ./7blosxom.cgi/fuga.txt/2003/////foo1/11////bar2/30 
181: nobodyさん [sage] 03/12/03 02:13 ID:??? AAS
 >>180 
 1月ダメじゃん…。 
  
 :($m=$_-1): => :($m=$_): 
 !($m&&$m-$M) => !($m&&$m-$M-1) 
182(4): nobodyさん [] 03/12/03 06:43 ID:4m1BwtbU(1) AAS
 >175 $p の指定に不具合あり。join忘れてた。 
  
 use CGI':all';use File::Find;$P=join'/',grep/^\D\w*$/,(@i=split'/',path_info);( 
 $Y,$M,$D)=grep/^\d+$/,@i;find sub{($d,$m,$y)=(localtime($t=(stat)[9]))[3..5];!( 
 !($Y&&$Y-$y-1900)&&!($M&&$M-$m-1)&&!($D&&$D-$d)&&/\.txt/&&(!$i[-1]||/^$i[-1]$/) 
 )or$e{$File::Find::name}=$t},"./$P";put header,start_html;for(sort{$e{$b}<=>$e{ 
 $a}}keys%e){open F,$_;s/^\.//;chomp($h=<F>);put h2(a{href,url.$_},$h),pre<Fhr 
 ;close F}put end_html; 
  
 若干仕様変更。 
 - カテゴリ名は /^\D\w*$/ 
 - ファイルの指定は、PATH_INFO の末尾のみ有効。 
 - findの対象はカレントディレクトリ以下のみ。(絶対パス指定できるのは、流石にちょっと 
  
 BTW,ファイルハンドルってスコープ抜けたら勝手にcloseされるんだっけ?perlって。 
183: nobodyさん [sage] 03/12/03 07:46 ID:??? AAS
 >182 
 テスト不十分だった。訂正 
 > $i[-1]!~/\.txt$/||/^$i[-1]$/
184: 7thread [sage] 03/12/03 09:43 ID:??? AAS
 use CGI":all";*i=*param;*x=*textfield;sub e{escapeHTML i pop}sub l{a{href,pop}, 
 pop}chdir G;-e($b=i(B)||e S)||open F,">$b";open F,"+<$b";eval{flock F,2};[<F>]; 
 s!\w+外部リンク:.+$!l$&,$&!eg,s/\n/br/eg,print F dt($.+1,':'.b(l e(N)||nobody,'mailto:' 
 .e M),':'.localtime),dd($_),"\n"if$_=e T;seek F,0,0;put header,start_html($b), 
 startform,$b?h1($b).dl(<F>).hidden(B,$b).l list,'?':ol(li[map{l$_,"?B=$_"}sort{ 
 -M$a<=>-M$b}<*>]).thread.x(S),br,submit,NAME,x(N),MAIL,x(M),br,textarea(T,'',6, 
 80,1),endform,end_html 
185(1): nobodyさん [sage] 03/12/03 20:55 ID:??? AAS
 7thread.cgi l10n for Japanese :) 
  
 #!/usr/local/bin/perl 
 use CGI":all";*i=*param;*x=*textfield;sub e{escapeHTML i pop}sub l{a{href,pop}, 
 pop}chdir G;-e($b=i(B)||e S)||open F,">$b";open F,"+<$b";eval{flock F,2};[<F>]; 
 s!\w+外部リンク:.+$!l$&,$&!eg,s/\n/br/eg,print F dt($.+1,':'.b(l e(N)||'ナナシ','mailto:'. 
 e M),':'.localtime),dd($_),"\n"if$_=e T;seek F,0,0;put header(-charset=>$c= 
 Shift_JIS),start_html(-title=>$b||$0,encoding,$c,lang,ja),startform,$b?h1($b). 
 dl(<F>).hidden(B,$b).l 'スレ','?':ol(li[map{l$_,"?B=$_"}sort{-M$a<=>-M$b}<*>]).'ス 
 レ'.x(S),br,submit,Name,x(N),Mail,x(M),br,textarea(T,'',6,80,1),endform,end_html 
  
 >>182 
 検証方法が思いつかず…。>スコープ抜けで close 
186(4): nobodyさん [sage] 03/12/03 23:13 ID:??? AAS
 7blosxom.cgi l10n for Japanese 
 start_html に -title=>$0 入れると7行に収まらなかった(苦)。 
  
 #!/usr/bin/perl 
 use CGI':all';use File::Find;($Y,$M,$D)=grep/^\d+$/,@i=path_info=~m|/([^/]+)|g; 
 $R=$i[-1]=~/\.txt$/?pop@i:'\.txt';find sub{($d,$m,$y)=(localtime($t=(stat)[9])) 
 [3..5];$e{$File::Find::name}=$t if!($Y&&$Y-$y-1900)&!($M&&$M-$m-1)&!($D&&$D-$d) 
 &/$R$/},$P=join('/','.',grep!/\.\.|^\d+$/,@i);put header(-charset=>$c='EUC-JP') 
 ,start_html(-encoding=>$c,lang,ja);for(sort{$e{$b}<=>$e{$a}}keys%e){open F,$_; 
 s/^\.//;chomp($h=<F>);put h2(a{href,url.$_},$h),pre<Fhr}put end_html 
  
 >>182 
 '..' さえ防いだら大丈夫な気も… 
 既に開かれてるファイルハンドルを open し直すと、開いていたファイルは 
 close されてから新しいファイルを open するので、close は明示しなくても 
 可な筈。 
 外部リンク[html]:perldoc.com 
187: nobodyさん [sage] 03/12/03 23:57 ID:??? AAS
 >>186 
 ちと修正。 
  
 #!/usr/bin/perl 
 use CGI':all';use File::Find;($Y,$M,$D)=grep/^\d+$/,@i=path_info=~m|/([^/]+)|g; 
 $R=$i[-1]=~/\.txt$/?pop@i:'.txt';find sub{($d,$m,$y)=(localtime($t=(stat)[9]))[ 
 3..5];$e{$File::Find::name}=$t if!($Y&&$Y-$y-1900)&!($M&&$M-$m-1)&!($D&&$D-$d)& 
 /\Q$R\E$/},join'/','.',grep!/\.\.|^\d+$/,@i;put header(-charset=>$c='EUC-JP'), 
 start_html(-encoding=>$c,lang,ja);for(sort{$e{$b}<=>$e{$a}}keys%e){open F,$_; 
 s/^\.//;chomp($h=<F>);put h2(a{href,url.$_},$h),pre<Fhr}put end_html 
188: nobodyさん [sage] 03/12/04 01:07 ID:??? AAS
 なにこのすれ(;´Д`) 
189(1): 128 [] 03/12/04 03:24 ID:h3ZU5uFM(1/2) AAS
 皆、お疲れ〜。 
 元気っぽいですな。 
  
 >>185 
 7thread 修正どうもです。かなりいけてました。 
 charset()を使わないと、escapeHTMLで文字化けが起こりますね。(「機能」とか) 
 EUCにしようかとも思ったんだけど。 
  
 #!/usr/local/bin/perl 
 use CGI":all";charset$c=Shift_JIS;*i=*param;*x=*textfield;sub l{a{href,pop},pop 
 }sub e{escapeHTML i pop}chdir G;$b=e(B)||e S;open F,"+>>$b";flock F,2;[<F>];$t= 
 'スレッド';s!\w+外部リンク:.+$!l$&,$&!emg,s/\n/br/eg,print F dt($.+1,':'.b(l e(N)||'七氏', 
 'mailto:'.e M),':'.gmtime),dd($_),"\n"if$_=e T;seek F,0,0;put header,start_html 
 (-title=>$b||$t,encoding,$c,lang,ja,style,[<DATA>]),startform,h1($b||$t),$b?dl( 
 <F>).hidden(B,$b).l $t,'?':ol(li[map{l$_,"?B=$_"}sort{-M$a<=>-M$b}<*>]).$t.x(S) 
 ,br,submit,Name,x(N),Mail,x(M),br,textarea(T,'',7,80,1),endform,end_html
190: 128 [] 03/12/04 03:32 ID:h3ZU5uFM(2/2) AAS
 オオボケでした。 
 開発中のを送ってしまった。 
  
 こっちです。 
  
 use CGI":all";charset$c=Shift_JIS;*i=*param;*x=*textfield;sub l{a{href,pop},pop 
 }sub e{escapeHTML i pop}chdir G;$b=e(B)||e S;open F,"+>>$b";flock F,2;[<F>];$t= 
 'スレッド';s!\w+外部リンク:.+$!l$&,$&!emg,s/\n/br/eg,print F dt($.+1,':'.b(l e(N)||'七氏', 
 'mailto:'.e M),':'.gmtime),dd($_),"\n"if$_=e T;seek F,0,0;put header,start_html 
 (-title=>$b||$t,encoding,$c,lang,ja),startform,h1($b||$t),$b?dl(<F>).hidden(B, 
 $b).l $t,'?':ol(li[map{l$_,"?B=$_"}sort{-M$a<=>-M$b}<*>]).$t.x(S),br,submit, 
 Name,x(N),Mail,x(M),br,textarea(T,'',7,80,1),endform,end_html 
191: nobodyさん [sage] 03/12/04 06:04 ID:??? AAS
 >>189 
 > charset()を使わないと、escapeHTMLで文字化け 
 あぁ、確かに ad hoc な事やってますな…。相変わらず CGI.pm はダサい。:< 
  
 #!/usr/bin/perl 
 use CGI":all";charset$c=Shift_JIS;*i=*param;*x=*textfield;sub l{a{href,pop},pop 
 }sub e{escapeHTML i pop}sub r{seek F,0,0}chdir G;($b=e(B)||e S)=~m![./]!&¨ 
 open F,"+>>$b";flock F,2;r;[<F>];s!\w+外部リンク:.+!l$&,$&!eg,s/\n/br/eg,print F dt($.+ 
 1,':'.b(l e(N)||'七氏','mailto:'.e M),':'.localtime),dd($_),"\n"if$_=e T;r;$t= 
 'スレ';put header,start_html(-title=>$b||$t,encoding,$c,lang,ja),startform,$b?h1( 
 $b).dl(<F>).hidden(B,$b).l $t,'?':ol(li[map{l$_,"?B=$_"}sort{-M$a<=>-M$b}<*>]). 
 $t.x(S),br,submit,Name,x(N),Mail,x(M),br,textarea(T,'',7,80,1),endform,end_html 
  
 ・レス番号が増えないのを fix 。 
 ・スレタイに [./] は使用不可 (「../7thread.cgi」なんてスレ立てられると…) 。 
 ・gmtime は流石にどうかと思う。 
 ・上記改造のしわ寄せを h1 周りに。 
192: nobodyさん [] 03/12/04 21:36 ID:b7RTKokI(1) AAS
 7thread 差分 
 < *i=*param 
 < sub e{escape i pop} 
 > sub e{escape param pop} 
 > -title=>$b=($t='スレ') 
  
 >186 thx URL 
 なるほど、close省略出来たんだ。 
 FileHandle にはスコープは関係なかったね。IO::Fileと勘違いしてた。 
  
 blosxom ... 残り1行じゃFlavourは無理かなぁ 
193(2): 128 [] 03/12/05 03:38 ID:2kvaGCEL(1) AAS
 乙カレーっす。 
  
 7thread ログの形式を変えてみました。 
 今までのログは利用できません。 
  
 あと__DATA__以降にスタイルシートを指定できるようにしました。 
  
 #!/usr/bin/perl 
 use CGI":all";charset$c=Shift_JIS;*i=*param;*x=*textfield;sub l{a{href,pop},pop 
 }sub e($){escapeHTML i pop}chdir G;($F=e B||e S)=~m![./]!?die:open F,">>$F";$t= 
 'スレ';$d=e N||'七氏';flock F,2;s!\w+外部リンク:.+!l$&,$&!eg,s/\n/br/eg,print F li(b(e M? 
 l$d,'mailto:'.e M:$d),localtime.p$_)if$_=e T;open F;$/='';put header,start_html 
 (-title=>$F||$t,-style=><DATAencoding,$c,lang,ja),startform,h1($F||$t),$F?ol( 
 <F>).hidden(B,$F).l $t,'?':ol(li[map{l$_,"?B=$_"}sort{-M$a<=>-M$b}<*>]).$t.x(S) 
 ,br,submit,Name,x(N),Mail,x(M),br,textarea(T,'',7,80,1),endform,end_html 
__DATA__ 
 h1{color:red; font-size:140%;} 
 p {margin:0; padding:0.5em; background:#EEF;}
上下前次1-新書関写板覧索設栞歴
あと 259 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.012s