package RDW; use strict; use warnings; use Carp; require Exporter; our( $VERSION, @ISA, @EXPORT ); $VERSION = "0.1"; @ISA = qw(Exporter); sub rdw_open { my $self; my $class = shift; my $file = shift; $file =~ s/^/{FILE} = $fh; #$self->{FILENAME} = $filename; bless $self, $class; return $self; } sub rdw_close { my $self = shift; my $fh = $self->{FILE}; close($fh) or return undef; return 1; } sub read_rdw { my $self = shift; my $fh = $self->{FILE}; my ( $rec_len, $rc, $len, $ret_val ); # Read record length $rc = sysread( $fh, $rec_len, 2 ); ( !defined($rc) ) && die "ERROR: rdw_read() failed read.\n"; $len = unpack( "S", $rec_len ); # Read record data if ( !defined($len) ) { return undef; } $rc = sysread( $fh, $ret_val, $len ); ( !defined($rc) ) && die "ERROR: rdw_read() failed read.\n"; # Return record data return $ret_val; } sub write_rdw { my $self = shift; my $fh = $self->{FILE}; my $line = join "", @_; print( $fh pack( "S", length($line) ), $line ) or croak "Can't write record to file: $!"; }