sub walkdown{ my($dir,$header) = @_; my(@dir); #local(*DIR); opendir(DIR,$dir) or die "Can't open $dir!"; foreach(readdir(DIR)){ next if $_ eq '.' or $_ eq '..'; push(@dir,$_) if -d "$dir/$_"; } closedir(DIR);
$clip = Win32::Clipboard() or die "もうしらん"; #クリップボードオブジェクトの取得 $dir = shift || die "usage: perl walkdown.pl dirname"; $output = ""; #global $output .= "$dir\n"; &walkdown($dir,""); $clip->Set($output); #出力をセット
sub walkdown{ my($dir,$header) = @_; my(@dir); #local(*DIR); opendir(DIR,$dir) or die "Can't open $dir!"; foreach(readdir(DIR)){ next if $_ eq '.' or $_ eq '..'; push(@dir,$_) if -d "$dir/$_"; } closedir(DIR);
You should note that SDBM won't work reliably on FAT or FAT32 file systems (a percentage of records written are not retrievable). That means you'll have to use DB_File on Windows 9x if you want it to work reliably. Besides, it saves four characters when typing the program:
>>Besides, it saves four characters when typing the program >これがよくわからないです。・・ おそらく、 「それに、プログラムを打ち込む際、四文字分だけ打たなくて済むよ」 云々は、その上に例として挙げられているスクリプトについて use SDBM_File; が、 use DB_File; に、(二文字分) tie(%h,'SDBM_File','junk136',O_RDWR|O_CREAT,0640) or die "Oops, $!\n"; が、 tie(%h,'DB_File','junk136',O_RDWR|O_CREAT,0640) or die "Oops, $!\n"; に(二文字分)なるので、(2+2=)四文字分タイプ量が少なくなるから、 DB_Fileの方がお奨めだよ、ということを(半ば冗談めかして)書いただけでしょう。 (間違ってたら恥ずかしいな~)
>>318 なるほど。 my ($a,$b,$c)=($_,$_,$_); より、 my $a=$i; my $b=$i; my $c=$i; の方が早いのですね。(む~何故だろう) ともかくも、ありがとうございます。 >foreach ( 1 .. 1000000 ) こうすると、一気に要素数が1000000の配列が確保されてしまいますよ~
>>433 って、perldoc perldocを読んだら、 ---------- C<perldoc> will use, in order of preference, the pager defined in C<PERLDOC_PAGER>, C<MANPAGER>, or C<PAGER> before trying to find a pager on its own. (C<MANPAGER> is not used if C<perldoc> was told to display plain text or unformatted pod.) One useful value for C<PERLDOC_PAGER> is C<less -+C -E>. ---------- ってはじめから書いてあるやん。結局、 SET PAGER=less か、 SET PERLDOC_PAGER=less とすればlessで読めると思います。
>>736 とりあえず、ローカルで #!/usr/bin/perl -w use File::Copy; eval{ copydir("src","to"); } print $@ if $@ ne ""; を実行して、出てくるエラーメッセージを確認した方がいいと思う。 自分の推測では Undefined subroutine &main::copydir called at xxx line x. だと思うがなあ。しかし、copydirはドキュメントにはあるが、 ソースを見ても何処にも定義されていないみたいだが・・・(妙だ) (ActivePerl5.6 Build622) ところであまり関係ないが、ログの入ったディレクトリはサブディレクトリを持つの?
$from = "./basedir"; $to = "./backupdir"; opendir(F,$from) or die "Can't open $from"; foreach(readdir(F)){ next if "$_" eq "." or $_ eq ".."; if(-f "$from/$_"){ copy("$from/$_","$to/$_") or die $!; } } closedir(F);
しまった~>>848は、 open(F,"file") || die "Can't open"; open(F,"file") || (die "Can't open"); open F,"file" or die "Can't open"; open(F,"file") || do {die "Can't open}"; open F,"file" || die "Can't open"; open(F,"file") or die "Can't open"; の間違い。
>848-849 あ。分かりました。(一応ですが・・・) open F , "file" || die "Can't open"; は、 "file" || die "Can't open" → "file" open(F,"file") こんな感じ(ちょっと間違っているかも)に解釈されるわけですね。