It's stated in some quarters that Perl's in-memory
filehandles supplant
the need for IO::Scalar, but when I tried to replace
IO::Scalar in a
test that invokes File::Slurp, it croaked. Memory
filehandles appear
to have a problem with sysread/syswrite that IO::Scalar does
not.
The point of the below example is to illustrate what works
and what
doesn't, not to suggest that mixing buffered and unbuffered
IO is a
good idea or anything to do with the issue. I tried mucking
around
with IO layers without making any difference. Does this
constitute a bug?
% perl
use strict;
use warnings;
use IO::Scalar;
# Writing:
my $ios_string;
my $ios_fh = IO::Scalar->new( $ios_string );
print {$ios_fh} "IO::Scalar: first linen";
syswrite $ios_fh, "Via syswrite", 12;
print "IOS: $ios_stringn";
my $perl_string;
open my $perl_fh, '>', $perl_string or die !$;
print {$perl_fh} "Perl: first linen";
syswrite $perl_fh, "Via syswrite", 12
and print "Perl: $perl_stringn"
or warn "*** Perl syswrite: $perl_string*** then:
$!n";
# Reading:
$ios_string = "IO::ScalarnIOS sysread";
$ios_fh = IO::Scalar->new( $ios_string );
print "IO::Scalar: first line: " .
<$ios_fh>;
sysread $ios_fh, my $ios_buf, 11;
print "IO::Scalar: sysread(11): $ios_bufn";
$perl_string = "PerlnPerl sysread";
open $perl_fh, '<', $perl_string or die $!;
print "Perl: first line: " . <$perl_fh>;
my $perl_buf;
sysread $perl_fh, $perl_buf, 12
and print "Perl: sysread(12): $perl_bufn"
or warn "*** Perl sysread: $!n";
__END__
IOS: IO::Scalar: first line
Via syswrite
*** Perl syswrite: Perl: first line
*** then: Bad file number
IO::Scalar: first line: IO::Scalar
IO::Scalar: sysread(11): IOS sysread
Perl: first line: Perl
*** Perl sysread: Bad file number
Observed on 5.8.8 and:
Summary of my perl5 (revision 5 version 9 subversion 5 patch
31750)
configuration:
Platform:
osname=linux, osvers=2.6.16-1.2133_fc5,
archname=i686-linux
uname='linux tweety 2.6.16-1.2133_fc5 #1 tue jun 6
00:52:14 edt
2006 i686 athlon i386 gnulinux '
config_args='-des -Dusedevel'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define,
usesocks=undef
use64bitint=undef, use64bitall=undef,
uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe
-I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe
-I/usr/local/include
-I/usr/include/gdbm'
ccversion='', gccversion='4.1.1 20060525 (Red Hat
4.1.1-1)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.4.so, so=so, useshrplib=false,
libperl=libperl.a
gnulibc_version='2.4'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef,
ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2
-L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV
PERL_MALLOC_WRAP
USE_LARGE_FILES USE_PERLIO
Locally applied patches:
DEVEL
Built under linux
Compiled at Aug 23 2007 11:57:31
INC:
lib
/usr/local/lib/perl5/5.9.5/i686-linux
/usr/local/lib/perl5/5.9.5
/usr/local/lib/perl5/site_perl/5.9.5/i686-linux
/usr/local/lib/perl5/site_perl/5.9.5
/usr/local/lib/perl5/site_perl
.
|