my $self = shift; my $fn = $self->[FILENAME]; my $fh = $self->[FILEHANDLE]; if ($fh) { seek $fh, 0, SEEK_END; return tell($fh)- $self->[STARTPOS]; } elsif ($fn) { return (-s $fn) - $self->[STARTPOS]; } else { return length($self->[BUFFER]); }
Data::TemporaryBag - Handle long size data using temporary file .
use Data::TemporaryBag; $data = Data::TemporaryBag->new; # add long string $data->add('ABC' x 1000); # You can use an overridden operator $data .= 'DEF' x 1000; ... $substr = $data->substr(2997, 6); # ABCDEF
Data::TemporaryBag module provides a bag object class handling long size data. The short size data are kept on memory. When the data size becomes over $Threshold size, they are saved into a temporary file internally.
Creates a bag object.
Clears $bag.
Adds $data to $bag. You can use an assignment operator '.=' instead.
Extracts a substring out of $bag. It behaves similar to CORE::substr except that it can't be an lvalue.
Creates a clone of $bag.
Gets data of $bag as a string. It is possible that the string is extremely long.
Gets length of data.
Returns if the data in $bag are defined or not.
Returns the file name if $bag is saved in a temporary file.
The threshold of the data size in kilobytes whether saved into file or not. Default is 10.
The maximum number of the opened temporary files. Default is 10.
Copyright 2001 Yasuhiro Sasama (ySas), <ysas@nmt.ne.jp>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::TemporaryBag, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::TemporaryBag
CPAN shell
perl -MCPAN -e shell install Data::TemporaryBag
For more information on module installation, please visit the detailed CPAN module installation guide.