/[VRac]/VRac.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /VRac.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 148 by dpavlin, Sun Aug 5 14:08:01 2007 UTC revision 156 by dpavlin, Sun Aug 5 17:28:55 2007 UTC
# Line 3  package VRac; Line 3  package VRac;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6  use Carp qw/confess croak/;  use Carp qw/confess croak cluck carp/;
7  use File::Slurp;  use File::Slurp;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    
# Line 201  sub append_to_file { Line 201  sub append_to_file {
201          my $path = shift || confess "no path?";          my $path = shift || confess "no path?";
202          my $bytes = join('', @_);          my $bytes = join('', @_);
203    
204            my $size = -s $path || 0;
205            my $len = length($bytes);
206    
207          open(my $fh, '>>', $path) || confess "can't open $path: $!";          open(my $fh, '>>', $path) || confess "can't open $path: $!";
208            print($fh $bytes);
209            my $pos = tell($fh);
210    
211            my $expected = $size + $len;
212            if ( $pos != $expected ) {
213                    carp "BUG: file grows too big got $pos, expected $expected !";
214                    truncate $fh, $expected;
215            }
216    
217            close($fh);
218    
         print $fh $bytes;  
219          warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes));          warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes));
220  }  }
221    

Legend:
Removed from v.148  
changed lines
  Added in v.156

  ViewVC Help
Powered by ViewVC 1.1.26