69 |
|
package Utilities::HashDB; |
70 |
|
use Utilities::DataItem; |
71 |
|
use FileHandle; |
72 |
< |
require 5.001; |
72 |
> |
require 5.004; |
73 |
|
|
74 |
|
sub new { |
75 |
|
my $class=shift; |
153 |
|
my $self=shift; |
154 |
|
my $filename=shift; |
155 |
|
|
156 |
+ |
use FileHandle; |
157 |
|
my $fh=FileHandle->new(); |
158 |
|
$fh->autoflush(1); |
159 |
< |
open ($fh, ">$filename") or die "Unable to open file $filename\n $!\n"; |
159 |
> |
|
160 |
> |
open ($fh, "> $filename") or die "Unable to open file $filename\n $!\n"; |
161 |
|
foreach $object ( @{$self->{dataitems}} ) { |
162 |
+ |
print $fh "\n"; |
163 |
|
$object->store($fh); |
164 |
|
} |
165 |
|
close $fh; |
170 |
|
my $filename=shift; |
171 |
|
my @arr=(); |
172 |
|
my $data; |
173 |
< |
my $fh=FileHandle->new(); |
174 |
< |
local *FH=$fh; |
173 |
> |
# Make $_ local so it's writable, otherwise you get errors like this: |
174 |
> |
# Modification of a read-only value attempted at |
175 |
> |
# /afs/cern.ch/user/s/sashby/w2/SCRAM/V1_0_3/src/Utilities/HashDB.pm line 178. |
176 |
> |
local $_; |
177 |
|
|
178 |
< |
if ($fh->open("<$filename")) |
178 |
> |
my $fh=FileHandle->new(); |
179 |
> |
open ($fh, "< $filename") or die "Unable to open file $filename\n $!\n"; |
180 |
> |
while (<$fh>) |
181 |
|
{ |
182 |
< |
# my $line; |
176 |
< |
# while ($line = $fh->getline()) |
177 |
< |
while (defined $fh) |
178 |
< |
{ |
179 |
< |
push @{$self->{dataitems}}, Utilities::DataItem->restore($fh); |
180 |
< |
} |
182 |
> |
push @{$self->{dataitems}}, Utilities::DataItem->restore($fh); |
183 |
|
} |
184 |
|
|
183 |
– |
# open ($fh, "<$filename") or die "Unable to open file $filename\n $!\n"; |
184 |
– |
|
185 |
– |
#while ( <$fh> ) { |
186 |
– |
# { print "...HashDB: in while loop","\n"; |
187 |
– |
# push @{$self->{dataitems}}, Utilities::DataItem->restore($fh); |
188 |
– |
# } |
185 |
|
close $fh; |
190 |
– |
#print "end restore","\n"; |
186 |
|
} |
187 |
|
|
188 |
|
# ------------------- Support Routines ------------ |