in reply to Re: Using an IO::File object stored in a Hash.
in thread Using an IO::File object stored in a Hash.
I am using Perl 5.24.0.
The problem is with reading from the IO::File object stored in the hash. All other portions of the example code work correctly.
Using readline, as suggested by BrowserUK fixes the problem; however, I do not understand why storing the IO::File object in a hash vs storing it in a scalar should have any affect. There must be some syntatic trick I am missing.
Sample 3:Sample 3 Output:use Path::Class; my $filename = "data.txt"; my $object = file($filename)->open('<:encoding(UTF-8)'); my %hash = ( 'handle' => $object); my $line1 = <$object>; my $line2 = readline($hash{'handle'}); my $line3 = <$hash{'handle'}>; my $line4 = <{$hash{'handle'}}>; print $line1, "\n"; print $line2, "\n"; print $line3, "\n"; print $line4, "\n"; close($object);
1 2 IO::File=GLOB(0x4de178) IO::File=GLOB(0x4de178)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using an IO::File object stored in a Hash.
by stevieb (Canon) on Jan 20, 2017 at 17:54 UTC | |
|
Re^3: Using an IO::File object stored in a Hash.
by kcott (Archbishop) on Jan 21, 2017 at 01:43 UTC |