package GeneralFile; use Exporter; @ISA = qw(Exporter); #公開したいサブルーチン @EXPORT = qw(); use strict; #use Crystal::MyUtility; BEGIN { } sub new { my ($module) = @_; my $this = {}; bless $this; $this->{'IN'} = ''; $this->{'OUT'} = ''; return $this; } sub DESTROY { my $this = shift; $this->Close(); } my $FILE; sub IN { my $this = shift; return $this->{'IN'}; } sub OUT { my $this = shift; return $this->{'OUT'}; } sub Close { my ($this) = @_; if($this->{'IN'} and $this->{'OUT'}) { close($this->{'IN'}); $this->{'IN'} = ''; $this->{'OUT'} = ''; } close($this->{'IN'}) if($this->{'IN'}); close($this->{'OUT'}) if($this->{'OUT'}); $this->{'IN'} = ''; $this->{'OUT'} = ''; $this->{'FileName'} = ''; $FILE = ''; } sub Open { my ($this, $openstr) = @_; $this->Close(); $openstr =~ s/^<(con|stdin)/<-/i; $openstr =~ s/^>(con|stdout)/>-/i; my $filename = $openstr; $filename =~ s/^[<>|\+]*//; $filename =~ s/|$//; $this->{'FileName'} = $filename; if($openstr =~ /^\+/) { my $ret = open($FILE, $openstr); $this->{'OUT'} = $this->{'IN'} = $FILE; return $ret; } if($openstr =~ /^[|<]/) { my $ret = open($FILE,$openstr); $this->{'IN'} = $FILE; return $ret; } if($openstr =~ /^>/ or $openstr =~ /|$/) { return open($FILE,$openstr); $this->{'OUT'} = $FILE; } return ''; } sub GetLine { my ($this) = @_; # my $io = $this->{'IN'}; my $line = < $FILE >; return $line; } 1;