polettix has asked for the wisdom of the Perl Monks concerning the following question:
I'm having a bit of troubles with in-memory filehandles, which seem to change shape behind the scenes, as the following example code seems to demonstrate.
#!/usr/bin/perl use strict; use warnings; use IO::Handle; my $data = 'some sample data here'; open my $fh, '<', \$data or die "open(): $!"; print {*STDERR} 'ref $fh yields ', ref $fh, "\n"; print_prop('$fh->can("opened")', $fh->can('opened')); print_prop('$fh->can("seek")', $fh->can('opened')); print_prop('$fh->can("seekable")', $fh->can('opened')); print_prop('$fh is IO::Handle', $fh->isa('IO::Handle')); print_prop('$fh->can("opened")', $fh->can("opened")); print_prop('$fh->opened()', $fh->opened()); print_prop('$fh->can("seek")', $fh->can("seek")); eval {print_prop('$fh->seek(0, 0)', $fh->seek(0, 0));} or print "$@"; print_prop('$fh is tied', tied $fh); close $fh; sub print_prop { my ($msg, $flag) = @_; print {*STDERR} $msg, '? ', ($flag ? 'yes' : 'no'), "\n"; return; } __END__ ref $fh yields GLOB $fh->can("opened")? no $fh->can("seek")? no $fh->can("seekable")? no $fh is IO::Handle? no $fh->can("opened")? no $fh->opened()? yes $fh->can("seek")? no Can't locate object method "seek" via package "IO::Handle" at memhandl +e.pl line 19. $fh is tied? no
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: In memory filehandles
by ysth (Canon) on Jan 26, 2006 at 11:56 UTC | |
by polettix (Vicar) on Jan 26, 2006 at 13:15 UTC | |
by ysth (Canon) on Jan 26, 2006 at 15:39 UTC | |
by polettix (Vicar) on Jan 27, 2006 at 09:38 UTC | |
by ysth (Canon) on Jan 27, 2006 at 10:31 UTC | |
| |
|
Re: In memory filehandles
by crouchingpenguin (Priest) on Jan 27, 2006 at 01:45 UTC | |
by polettix (Vicar) on Jan 27, 2006 at 09:26 UTC |