Changeset 1123 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix.pm
- Timestamp:
- 08/18/12 17:26:01 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix.pm
r1071 r1123 8 8 use LATMOS::Accounts::Log; 9 9 use Fcntl qw(:flock); 10 use Encode; 10 11 11 12 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; … … 76 77 sub _load_unix_file { 77 78 my ($self, $file, $callback) = @_; 79 my $enc = find_encoding($self->config('encoding') || 'iso-8859-14') 80 or do { 81 $self->log(LA_ERROR, "Cannot find encoding %s", $self->config('encoding') || 'iso-8859-15'); 82 return; 83 }; 78 84 open(my $handle, '<', $file) or do { 79 85 $self->log(LA_ERR, "Cannot open unix file `%s' for reading (%s)", $file, $!); … … 84 90 while (my $line = <$handle>) { 85 91 chomp($line); 92 $line = encode('utf-8', $line); 86 93 my @ch = split(':', $line); 87 94 $callback->(@ch); … … 195 202 sub _save_unix_file { 196 203 my ($self, $file, @data) = @_; 204 my $enc = find_encoding($self->config('encoding') || 'iso-8859-14') 205 or do { 206 $self->log(LA_ERROR, "Cannot find encoding %s", $self->config('encoding') || 'iso-8859-15'); 207 return; 208 }; 197 209 open(my $handle, '>>', $file) or do { 198 210 la_log(LA_ERR, "Cannot open unix file `%s' for writing (%s)", $file, $!); … … 202 214 truncate($handle, 0); 203 215 foreach my $line (@data) { 204 print $handle join(':', map { my $f = $_; $f =~ s/:/;/g; $f } map { defined($_) ? $_ : '' } @$line) . "\n"; 216 my $string = join(':', map { my $f = $_; $f =~ s/:/;/g; $f } map { defined($_) ? $_ : '' } @$line) . "\n"; 217 $string = decode('utf8', $string); 218 print $handle $string; 205 219 } 206 220 close($handle);
Note: See TracChangeset
for help on using the changeset viewer.