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
In reply to In memory filehandles by polettix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |