in reply to Propose addition to use warnings?

You must have done something weird in my_sub because for me, warnings already tell me that I'm using a closed filehandle:

#!/usr/bin/perl use strict; use warnings; open my $fh, '<', $0 or die "I can't read myself"; open my $fh2, '<', $0 or die "I can't read myself (2)"; my @lines = <$fh>; close $fh; sub my_sub { my( $this_fh, $line ) = @_; warn sprintf "At offset %d: %s", tell $this_fh, $line; }; while (my $line = <$fh2>) { my @data = my_sub($fh, $line); # copy/paste error, should have pas +sed $second_fh here # and of course a bunch of non-relevant stuff here } __END__ tell() on closed filehandle $fh at tmp.pl line 15. At offset -1: #!/usr/bin/perl tell() on closed filehandle $fh at tmp.pl line 15. At offset -1: ...

Maybe you can show us what you were doing in my_sub with the filehandle and where Perl didn't warn there?

Replies are listed 'Best First'.
Re^2: Propose addition to use warnings?
by haukex (Archbishop) on Nov 28, 2016 at 15:02 UTC

    Hi Corion,

    The way I understood perldigious' post is that the usage of the filehandle in my_sub is very rare, so more like warn sprintf "At offset %d: %s", tell $this_fh, $line if rand()<0.0001;, which makes the issue much harder to detect.

    Regards,
    -- Hauke D

      Yes, thanks for clarifying for me haukex. Corion is correct, there is a warning provided when the filehandle is attempted to be used by the subroutine, but that is a very rare occurrence due to an if it happens to be wrapped in, and to my shame, my test data didn't properly exercise that part of my code to make sure it was working when I wrote it (an oversight on my part).

      Just another Perl hooker - will code for food