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)
In reply to Re^2: Using an IO::File object stored in a Hash.
by jjs04
in thread Using an IO::File object stored in a Hash.
by jjs04
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |