in reply to Making my own PerlIO layer
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/^/</ if ( $file =~ m!^/?\w! ); open( my $fh, $file, @_ ) or return undef; $self->{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: $!"; }
Also, feel free to comment on the original module. Perhaps there's some modifications that could be made there that would make the work here easier.
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
|
|---|