in reply to Re^2: A Few Questions About IO::File
in thread A Few Questions About IO::File

When you chain the commands you will not get a handle to close the file. I have to admit that I am not so sure myself when the file will get closed...

Replies are listed 'Best First'.
Re^4: A Few Questions About IO::File
by tobyink (Canon) on Mar 18, 2013 at 15:30 UTC

    It will close when Perl hits the semi-colon, because that is when Perl realises the object has gone out of scope.

    Quick demo:

    use v5.14; package Foo { sub new { my $class = shift; say "new"; bless [] => $class; } sub some_method { my $self = shift; say "some_method"; return $self; } sub other_method { my $self = shift; say "other_method"; return 123; } sub DESTROY { my $self = shift; say "DESTROY"; } } say "START"; say Foo->new->some_method->other_method and say 456; say "END";

    DESTROY happens after "456" is printed, but before "END".

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name