Drkcore

31 08 2006 perl Tweet

File::Remoteのファイルハンドルを動的生成したかった

rshが必要な古いマシンで動くプログラムって、引数にファイルをとることが多い。つまり、インプットファイルをリモートに書き込む必要があるわけだ。nfsマウントでもいいかもしれないが、fstabが無駄にごちゃごちゃしてくるので好きではない。潔くNet::FTPでもよかったのだけど、この際File::Remoteを使ってみた。

で、このモジュールはなぜか

use FileHandle ();
my $fh = FileHandle->new();
open($fh, "test.txt");
close($fh);

みたいな書き方ができないし、じゃぁこれでどうだと

        $rh->open(RH, ">remote:/tmp/$rfile") or die $!;

これはuse Strictしてると

Bareword "RH" not allowed

とか怒られる。で結局、下の感じでフニュケたコードになってしまった。

{ # Bareword "RH" "LH" allowed
    no strict 'subs';

    my $lh = File::Remote->new();
    $lh->open(LH, "$file") or die $!;

    my $rh = File::Remote->new();
    $rh->open(RH, ">remote:/tmp/$rfile") or die $!;
    local $/;
    my $f = <LH>;
    print RH $f;
    $rh->close(RH);

    $lh->close(LH);

}

どう使うのが賢いやり方なんだろう。

$rh->open(*RH, ">remote:/tmp/$rfile") or die $!;

とでもするのがいいのか?

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021