use strict;
use IO::File;
+use Storable;
use Maasha::Common;
use Exporter;
}
+sub files_read_open
+{
+ # Martin A. Hansen, May 2009.
+
+ # Cats a number of files and returns a filehandle.
+
+ my ( $files, # full path to file
+ ) = @_;
+
+ # returns filehandle
+
+ my ( $file, $fh, $type, %type_hash, $file_string );
+
+ foreach $file ( @{ $files } )
+ {
+ Maasha::Common::error( qq(No such file: $file) ) if not -f $file;
+
+ $type = `file $file`;
+
+ if ( $type =~ /gzip compressed/ ) {
+ $type_hash{ 'gzip' } = 1;
+ } else {
+ $type_hash{ 'ascii' } = 1;
+ }
+ }
+
+ Maasha::Common::error( qq(Mixture of zipped and unzipped files) ) if scalar keys %type_hash > 1;
+
+ $file_string = join " ", @{ $files };
+
+ if ( $type =~ /gzip compressed/ ) {
+ $fh = new IO::File "zcat $file_string|" or Maasha::Common::error( qq(Could not open pipe: $!) );
+ } else {
+ $fh = new IO::File "cat $file_string|" or Maasha::Common::error( qq(Could not open pipe: $!) );
+ }
+
+ return $fh;
+}
+
+
sub file_write_open
{
# Martin A. Hansen, January 2004.
}
+sub file_store
+{
+ # Martin A. Hansen, December 2004.
+
+ # writes a data structure to file.
+
+ my ( $path, # full path to file
+ $data, # data structure
+ ) = @_;
+
+ Storable::store( $data, $path ) or Maasha::Common::error( qq(Could not write-open file "$path": $!) );
+}
+
+
+sub file_retrieve
+{
+ # Martin A. Hansen, December 2004.
+
+ # retrieves hash data structure
+ # (this routines needs to test if its a hash, array or else)
+
+ my ( $path, # full path to data file
+ ) = @_;
+
+ my ( $data );
+
+ $data = Storable::retrieve( $path ) or Maasha::Common::error( qq(Could not read-open file "$path": $!) );
+
+ return wantarray ? %{ $data } : $data;
+}
+
+
sub file_copy
{
# Martin A. Hansen, November 2008.