七行プログラミング (452レス)
1-

91: 02/11/27 20:42 ID:??? AAS
7wiki.cgi 、一旦まとめ。(w

#! perl
use CGI':all';$w='\b(([A-Z][a-z]+){2,})';($p)=(path_info||FrontPage)=~/$w/;$/=(
);$f=script_name."/";opendir D,".";if(open F,($m=param z)?">$p":$p){eval{flock
F,2};$_=CGI::escapeHTML($m||=<F>);eval{truncate F,0};seek F,0,0;print F$m;close
F}$_=pre($_).hr.ul map{li"".localtime((stat)[9]),$_}sort{-M$a<=>-M$b}grep/$w$/,
readdir D;s|$w|(!-f$1&&$1).a{href,$f.$1},-f$1?$1:"?"|eg;put header,start_html(
$p),h1($p),startform(0,$f.$p),textarea(z,$m,6,60),br,submit,endform,$_,end_html

・bare word が存在するので perl -w は不可。
・古い CGI.pm は escapeHTML を輸出しないので括弧が必要。
92
(2): 02/11/28 03:13 ID:??? AAS
use CGI':all';$w='\b(([A-Z][a-z]+){2,})';$f=script_name."/";opendir D,".";$/=()
;($p)=(path_info||FrontPage)=~/$w/;if(open F,($m=param z)?">$p":$p){eval{flock
F,2};$_=submit.endform.hr.pre CGI::escapeHTML($m||=<F>);eval{truncate F,0};seek
F,0,0;print F$m;close F}$_=br.$_.hr.ul map{li"".localtime((stat)[9]),$_}sort{-M
$a<=>-M$b}grep/$w$/,readdir D;s|$w|(!-f$1&&$1).a{href,$f.$1},-f$1?$1:"?"|eg;put
header,start_html($p),h1($p),startform(0,$f.$p).textarea(z,$m,6,60),$_,end_html

-w は >>86 の環境では付けないとCGIとして動かなかったんだけど・・
どうしてだろう?z maybe crash って warning 出すのはわかっていたけど
ちゃんと動いていたような気がする。(エラーログ今度ちゃんと見て来よう。

TextRule に Pod::Htmlを使おうとしたが、
pod2html はファイルを対象としているため実装を断念。
残り一行じゃ TextRuleは辛いかな・・URLのリンクくらいなら追加出来そう・・?
93
(1): 02/11/28 03:23 ID:??? AAS
あっ バグ・・・今気付いた。
open が失敗した時困るかな >>92
94
(1): 02/11/28 05:30 ID:??? AAS
>>88
アイコンと th 無くして、あと目に付いたトコだけザッと。

#! perl -w
use CGI':all';*p=*param;$d=path_info;$t=opendir D,".$d";$F=F;($c=$f=script_name
)=~s|/[^/]+$||;$R=REN;$C=CP;$D=DEL;p$D&&unlink p$F;put header,start_html(7files
),startform(0,$f),table(Tr[map{$i="$d/$_";($l,$s)=-d".$i"?($f.$i,'DIR'):($c.$i,
-s _);td({bgcolor,(white,eeeeff)[$t++%2]},[checkbox($F,0,$_,''),a({href,$l},$_)
,$s,"".localtime((stat)[9])])}sort grep!/^\./,readdir D]),(map{submit$_}$R,$C,
$D),endform,end_html
95: 02/11/28 05:55 ID:??? AAS
>>94 修正…。

use CGI':all';($c=$f=script_name)=~s|/[^/]+$||;$d=path_info;$t=opendir D,".$d";
$F=F;$M=MV;$C=CP;$R=RM;*p=*param;p$D&&unlink p$F;put header,start_html('7files'
),startform(0,$f),table(Tr[map{$i="$d/$_";($l,$s)=-d".$i"?($f.$i,'DIR'):($c.$i,
-s _);td({bgcolor,(white,eeeeff)[$t++%2]},[checkbox($F,0,$_,''),a({href,$l},$_)
,$s,"".localtime((stat)[9])])}sort grep!/^\./,readdir D]),(map{submit$_}$M,$C,
$R),endform,end_html
96: 02/11/28 06:10 ID:??? AAS
>>92
成る程、そういう環境もありますか。
warning 吐きまくるのはヤだなぁと思っただけなんで、
shebang line は適宜変更でいいですかのぅ。

つか valid な HTML にはあまりこだわってませんか。

URL リンクはこうかな…。
s|(http://[\w!#-;=?-@~]+)|a{href,$1},$1|eg;

>>93
困りました。:)
97
(1): 02/11/28 11:46 ID:??? AAS
>困りました。:)
ごめん。パズルに夢中でperl -cしかチェックしてなかったw
書きこみ、 新規ページ作成 テスト、以後気を付けます。テスト書こうっと

HTMLの構文チェックもしてません。出力はCGI.pm任せなので、
少なくともwelformedにはなってるはずだけど・・

7wiki.cgi 6行76桁
use CGI':all';$w='\b(([A-Z][a-z]+){2,})';$/=();$f=script_name;($p)=(path_info||
FrontPage)=~/$w/;opendir D,".";if(open F,($m=param z)?">$p":$p){eval{flock F,2}
;eval{truncate F,0};seek F,0,0;print F$m||=<F>;close F}$_=pre CGI::escapeHTML($
m).hr.ul map{li"".localtime((stat)[9]),$_}sort{-M$a<=>-M$b}grep/$w$/,readdir D;
s|$w|(!-f$1&&$1).a{href,"$f/$1"},-f$1?$1:"?"|eg;put header,start_html($p),h1($p
),startform(0,"$f/$p").textarea(z,$m,6,60),br,submit.endform.hr.$_,end_html
98
(1): 02/11/29 06:36 ID:??? AAS
>>97
うん、well-formed ではあるけど、pre に hr や ul が入ってるから
valid じゃないよね。

別にいちゃもん付けてるんじゃ無くて、七行に収まってる状態で更に
数 byte の為に valid な出力を諦めるか否かは好みの問題だから、
何としても縮める方針でやってるのかな、と。挙動が変更されたコード
見たら、何を意図してるか大体分かるでしょ。

で、俺は shebang 込みで七行派だから、7wiki.cgi に関しては >>97
下ので完成気分。shebang 無し七行で続けるなら、それはそれで参加
させてもらうけどね。

#! perl -w
use CGI':all';$w='\b(([A-Z][a-z]+){2,})';$/=();$f=script_name;($p)=(path_info||
FrontPage)=~/$w/;opendir D,".";if(open F,($m=param z)?">$p":$p){eval{flock F,2}
;eval{truncate F,0};seek F,0,0;print F$m||=<F>;close F}$_=pre(CGI::escapeHTML($
m)).hr.ul map{li"".localtime((stat)[9]),$_}sort{-M$a<=>-M$b}grep/$w$/,readdir D
;s|$w|(!-f$1&&$1).a{href,"$f/$1"},-f$1?$1:"?"|eg;put header,start_html($p),h1($
p),startform(0,"$f/$p"),textarea(z,$m,6,60),br,submit,endform,hr,$_,end_html
99
(1): 02/11/29 08:01 ID:??? AAS
7files.cgi

use CGI':all';*p=*param;($c=$f=script_name)=~s|/[^/]+$||;$d=path_info;opendir D
,$e=".$d/";sub cp{}$F=p(F);$N=$e.p(N);($_=p(S))=~/MV/?rename$F,$N:/CP/?cp$F,$N:
/RM/?unlink$F:0;put header,start_html('7files'),startform(0,"$f$d"),table(Tr[
map{$i="$d/$_";($l,$s)=-d".$i"?($f.$i,DIR):($c.$i,-s _);td({bgcolor,(silver,
white)[$t++%2]},[checkbox(F,0,".$i",''),a({href,$l},$_),$s,"".localtime((stat)[
9])])}sort grep!/^\./,readdir D]),textfield(N),map(submit(S,$_),MV,CP,RM),
endform,end_html

rename 実装。copy が悩み処ですな。
100
(3): 02/11/29 08:04 ID:??? AAS
rename の仕方:
変更したいファイルにチェック、textfield に変更後の名前を入れて MV
101
(1): 02/11/29 09:06 ID:??? AAS
>>98
お疲れ様 && ありがとう。色々と勉強になりました。

no strict で bare word 使い始めた当たりから
短くすることを優先させてました。use strictなしって時点で
すでに気持ち悪かったwので「汚くても動けばいいや」って感じだった

HTMLもチェックしていなかった位だから、当然拘っていませんでした
(HTMLは、7行って時点で最初から諦めていたかもしれない

ただ、valid な出力にするとなると、
CGI.pm の textarea が rows,colsの属性の値をクオートしない。
br, hr は、p,div,h[1-6] 等の親要素が必要
等々、新たな課題が出てくるんじゃないかな?
102
(1): 02/11/29 09:30 ID:??? AAS
動作チェックしてないけど。

use File::Copy;
sub cp{ map{ -f$_&©($_,"copy_of_$_") }p(F) }
103: 02/11/29 11:06 ID:??? AAS
>>101
ありゃ。本当に全然拘ってなかったのね。w
なら 3 文字加えてピッタリ 6x79 。

use CGI':all';$w='\b(([A-Z][a-z]+){2,})';$/=();$f=script_name;($p)=(path_info||
FrontPage)=~/$w/;opendir D,".";if(open F,($m=param z)?">$p":$p){eval{flock F,2}
;eval{truncate F,0};seek F,0,0;print F$m||=<F>;close F}$_=pre(CGI::escapeHTML($
m)).hr.ul map{li"".localtime((stat)[9]),$_}sort{-M$a<=>-M$b}grep/$w$/,readdir D
;s|$w|(!-f$1&&$1).a{href,"$f/$1"},-f$1?$1:"?"|eg;put header,start_html($p),h1($
p),startform(0,"$f/$p"),p(textarea(z,$m,6,60),br,submit),endform,hr,$_,end_html

・hr はブロック要素なので無問題。
・form 内の各要素がインライン要素なので p で囲む。
・textarea の属性値クォートは 7wiki.cgi 側でなく CGI.pm 側の
 問題だし、最近の CGI.pm なら直ってるので考えない。w

これでかなり valid.
104: 02/11/29 11:54 ID:??? AAS
>>102
そか…モジュールという手が…。(´Д`;

use CGI':all';use File::Copy;$d=path_info;($c=$f=script_name)=~s|/[^/]+$||;*p=*
param;opendir D,$e=".$d/";$F=p(F);$N=$e.p(N);$w=($_=p(S))=~/MV/?rename$F,$N:/CP
/x?copy$F,$N:/RM/?unlink$F:1;put header,start_html('7files'),startform(0,"$f$d"
),table(Tr[map{$i="$d/$_";($l,$s)=-d".$i"?($f.$i,DIR):($c.$i,-s _);td({bgcolor,
(silver,white)[$t++%2]},[checkbox(F,0,".$i",''),a({href,$l},$_),$s,"".localtime
((stat)[9])])}sort grep!/^\./,readdir D]),textfield(N),map(submit(S,$_),MV,CP,
RM),endform,end_html

copy の仕方も rename と一緒。
105: 02/11/30 03:07 ID:??? AAS
> ありゃ。本当に全然拘ってなかったのね。w
えぇ。行末の桁揃えに夢中だったので。。w

use CGI':all';use File::Copy;$d=path_info;*p=*param;opendir D,$e=".$d/";$F=p(F)
;$N=$e.p(N);($_=p(S))=~/MV/?move$F,$N:/CP/?copy$F,$N:/RM/?unlink p(F):1;($c=$f=
script_name)=~s|/[^/]+$||;put header,start_html('7files'),startform(0,$f.$d),
table(Tr[map{$i="$d/$_";($l,$s)=-d".$i"?($f.$i,DIR):($c.$i,-s _);td({bgcolor,(
white,silver)[$t^=1]},[checkbox(F,0,".$i",''),a({href,$l},$_),$s,"".localtime((
stat)[9])])}sort grep!/^\./,readdir D]),textfield(N),map(submit(S,$_),MV,CP,RM)
,endform,end_html

- rename --> File::Copy#move に変更。
ファイルをチェックして、テキストにディレクトリ名を入れてMVで
ファイルをディレクトリに移動します。

= TODO
mkdir, rmdir
106: 02/12/01 01:22 ID:??? AAS
mkdir, rmdir 実装。特にヒネりもなく…。

use CGI':all';use File::Copy;$d=path_info;($c=$f=script_name)=~s|/[^/]+$||;*p=*
param;opendir D,$e=".$d/";$F=p(F);$N=$e.p(N);$_=p(S);/MV/?move$F,$N:/CP/?copy$F
,$N:/RM/?unlink$F:/MD/?mkdir$N,511:/RD/?rmdir$F:1;put header,start_html('7files
'),startform(0,$f.$d),table(Tr[map{$i="$d/$_";($l,$s)=-d".$i"?($f.$i,DIR):($c.$
i,-s _);td({bgcolor,(white,silver)[$t^=1]},[checkbox(F,0,".$i",''),a({href,$l},
$_),$s,"".localtime((stat)[9])])}sort grep!/^\./,readdir D]),textfield(N),map(
submit(S,$_),MV,CP,RM,MD,RD),endform,end_html

table を何とかせんと、劇的には縮まらな気。
107: 02/12/01 05:42 ID:??? AAS
bgcolorを削って、chdirにしてみた・・

use CGI':all';use File::Copy;$d=path_info;*p=*param;chdir".$d";$N=p N;$F=p F;$_
=p S;/MV/?move$F,$N:/CP/?copy$F,$N:/RM/?unlink$F:/MD/?mkdir$N,511:/RD/?rmdir$F:
1;opendir D,".";($c=$f=script_name)=~s|/[^/]+$||;put header,start_html('7files'
),startform(0,$f.$d),table(Tr[map{td[checkbox(F,0,$_,''),a({href,-d$_?"$f$d/$_"
:"$c$d/$_"},$_),-s||DIR,"".localtime((stat)[9])]}sort grep!/^\./,readdir D]),
textfield(N),map(submit(S,$_),MV,CP,RM,MD,RD),endform,end_html

p(F); を p F; って表記するのも環境/バージョンに依存するのかな?
108
(1): 02/12/01 07:42 ID:??? AAS
give up 気味。(´Д`;

use CGI':all';use File::Copy;$d=path_info;*b=*param;chdir".$d";$N=b N;$F=b F;%m
=qw(MV move$F,$N CP copy$F,$N RM unlink$F MD mkdir$N,511 RD rmdir$F);eval$m{b S
};opendir D,".";($c=$f=script_name)=~s|/[^/]+$||;put header,start_html('7files'
),startform(0,$f.$d),table(Tr[map{td[checkbox(F,0,$_,''),a({href,(-d$_?$f:$c).
"$d/$_"},$_),-s||DIR,"".localtime((stat)[9])]}sort grep!/^\./,readdir D]),
textfield(N),(map{submit S,$_}keys%m),endform,end_html

param のエイリアスを b にしたのは、p 要素の p() を
使えるようにする為の布石。

> p(F); を p F; って表記
大丈夫っぽいです。
109
(1): 02/12/01 08:40 ID:??? AAS
ディレクトリは別にサイズ取れない訳じゃないので
-s||DIR は駄目ですな…。
110: 02/12/01 12:51 ID:??? AAS
>109
Win/ActivePerlだとディレクトリのサイズ0が返ってきていた
これも環境に依存するのか。。 -d _?DIR:-s _ でok ?

use CGI':all';use File::Copy;$_='$d=path_info;*b=*param;chz".$d";$N=b N;$F=b F;
%m=qw(MV move$F,$N CP copy$F,$N RM unlink$F MD mkz$N,511 RD rmz$F);eval$m{b S}
;openz D,".";($c=$f=script_name)=~s|/[^/]+$||;put header,start_html("7files")
,startform(0,$f.$d),table(Tr[map{td[checkbox(F,0,$_,""),a({href,(-d$_?$f:$c)
."$d/$_"},$_),-d _?DIR:-s _,"".localtime((stat)[9])]}sort grep/^[^.]/,readz
D]),textfield(N),(map{submit S,$_}keys%m),endform,end_html';s/z/dir/g;eval

置換してスクリプト長くなってるし。。。そろそろ give up

>108 のファイルサイズを直して、完成かな
111: 02/12/01 14:28 ID:??? AAS
せっかくだから空ファイル作成 (MF) など付けてみる。

use CGI':all';use File::Copy;$d=path_info;*b=*param;chdir".$d";$N=b N;$F=b F;%m
=(qw(MV move$F,$N CP copy$F,$N RM unlink$F MD mkdir$N,511 RD rmdir$F MF),'open
F,">$N"');eval$m{b S};opendir D,".";($c=$f=script_name)=~s|/[^/]+$||;put header
,start_html("7files"),startform(0,$f.$d),table(Tr[map{td[checkbox(F,0,$_,""),a(
{href,(-d$_?$f:$c)."$d/$_"},$_),-d$_?DIR:-s,"".localtime((stat)[9])]}sort grep!
/^\./,readdir D]),p(textfield(N),map{submit S,$_}keys%m),endform,end_html
112: 02/12/02 07:11 ID:??? AAS
Rss出力と検索機能 4 7wiki.cgi

---- 7search.cgi
use CGI':all';$f=script_name;$s=param S;opendir D,".";if($s){map{$t=$_;if(open
F,$t){eval{flock F,2};while(<F>){chomp;if(/\Q$s\E/io){push(@r,li(a{href,$t},$t)
," - $_");last}}close F}}sort grep/^[^.]+$/,readdir D}put header,start_html(
'7search'),startform(0,$f),p(textfield(S),submit),endform,hr,ul(@r),end_html

---- 7rss.cgi
use CGI qw/:all channel item textinput link name/;($p)=script_name=~m|(.+)/[^/]
+$|x;$s=server_name.$p;opendir D,".";$w='7wiki';put"Content-type:text/xml\n\n",
qq|<?xml version="1.0"?>\n<rdf:RDF xmlns:rdf="外部リンク:www.w3c.org|,
q|df-syntax-ns#" xmlns="外部リンク:my.netscape.com">|,channel(title
($w),link"$s/$w.cgi"),(map{item(title($_),link"$s.$_")."\n"}sort grep/^[^.]+$/,
readdir D),textinput(title($w),link("$s/7search.cgi"),name(S)),"\n</rdf:RDF>";

# CGI.pm v2.69 以降 or c2.67 wiz xhtml tag
- link() の動作がちょっと不安。
113: 02/12/02 07:39 ID:??? AAS
7rss.cgi
> item(title($_),link"$s.$_")."
< item(title($_),link"$s.cgi/$_")."
114: 02/12/02 08:06 ID:??? AAS
#7search.cgi - v0.02 fixed some bugs
use CGI':all';($c=$f=script_name)=~s|/[^/]+$||;$s=param S;if($s){opendir D,".";
map{$t=$_;if(open F,$t){eval{flock F,2};while(<F>){chomp;if(/\Q$s\E/io){push@r,
li(a({href,"$c/7wiki.cgi/$t"},$t)," $_");last}}close F}}sort grep/^[^.]+$/,
readdir D}put header,start_html('7search'),startform(0,$f),p(textfield(S),
submit),endform,hr,ul(@r),end_html

#7rss.cgi - v0.02 show latest 15 articles
use CGI qw/:all channel item textinput link name/;($p)=script_name=~m|(.+)/[^/]
+$|x;$s=server_name.$p;opendir D,".";$w='7wiki';put"Content-type:text/xml\n\n",
qq|<?xml version="1.0"?>\n<rdf:RDF xmlns:rdf="外部リンク:www.w3c.org|,
q|df-syntax-ns#" xmlns="外部リンク:my.netscape.com">|,channel(title
($w),link"$s/$w.cgi"),(map{item title($_),link"$s.cgi/$_"}sort{-M$a<=>-M$b}grep
/^[^.]+$/,readdir D)[0..14],textinput(title($w),link("$s/7search.cgi"),name S),
"\n</rdf:RDF>";
115: 02/12/02 17:31 ID:??? AAS
# 7rss.cgi v0.03

use CGI qw/:all channel item textinput link name/;opendir D,".";$w='7wiki';($p)
=url=~m|^(.+)/[^/]+$|;put header('text/xml'),qq|<?xml version="1.0"?>\n<rdf:RD|
,'F xmlns:rdf="外部リンク:www.w3c.org" xmlns="外部リンク:my.'
,'netscape.com/rdf/simple/0.9/">',channel(title($w),link"$p/$w.cgi"),(map{item
title($_),link"$p/$w.cgi/$_"}sort{-M$a<=>-M$b}grep/^[^.]+$/,readdir D)[0..14],
textinput(title($w),link("$p/7search.cgi"),name S),"\n</rdf:RDF>";
116: 02/12/21 03:14 ID:RF/wn3c8(1) AAS
7threadキボンヌ
117
(1): 02/12/30 09:38 ID:??? AAS
拙作をまとめていた isweb のサイト、広告ウザいので引っ越し。
ついでに配布体裁整え。外部リンク:calorymate.s15.xrea.com

7wiki と 7files 、参加作という事でサイトに載っけていいですか?
118: 'a';$happy = new Year; 02/12/31 15:36 ID:??? AAS
>>117
Take It free.

<一応、ベースとなるものを書いたモノです
自分が代表してレスしていいのかわかんないけど &&
このスレッド的にはどうなのか知らないけど・・・、

このまま過去ログに埋もれて日の目を見ないよりも、
公開して保守して貰えるのなら、そっちの方がいいよな
て事でお願いします。
ついでに、7rss, 7search も載せてもらえるとうれしいな。

package Year;sub new{bless{},shift}
119: 03/01/15 02:35 ID:??? AAS
忘れた頃に。(w

--- 7search.cgi
use CGI':all';put header,start_html('7search'),startform(0,$_=script_name),p(
textfield(S),submit),endform,hr;if($s=param S){m|/[^/]+$|;$c=$`;opendir D,".";
for(sort grep/^\w+$/&-f,readdir D){if(open F,$t=$_){eval{flock F,2};/\Q$s\E/io
&&push(@r,li(a({href,"$c/7wiki.cgi/$t"},$t)," $_"))&&next while<F>;}}@r&&put ul
@r}put end_html

--- 7rss.cgi
use CGI qw/:all channel item textinput link name/;opendir D,".";$w='7wiki';url
=~m|[^/]+$|;$p=$`;put header('text/xml'),join"\n",'<?xml version="1.0"?>',
'<rdf:RDF xmlns:rdf="外部リンク:www.w3c.org" xmlns="http'
.'外部リンク:my.netscape.com">',channel(title($w),link"$p$w.cgi"),(map{
item title($_),link"$p$w.cgi/$_"}sort{-M$a<=>-M$b}grep/^\w+$/&-f,readdir D)[0..
14],textinput(title($w),link($p.'7search.cgi'),name S),'</rdf:RDF>'

つー事で載せときました。
120: 山崎渉 [(^^)sage] 03/01/15 13:41 ID:??? AAS
(^^)
1-
あと 332 レスあります
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ

ぬこの手 ぬこTOP 0.013s