http://www.perlmonks.org?node_id=1056765


in reply to exports -- which module exports are used?

Minor issue: I think the line numbers that are reported are incorrect:
$ cat foo.pl #!/usr/bin/env perl use Carp; carp('boo'); # This is line 3 $ exports foo.pl foo.pl: 7: carp('boo'); # This is line 3 carp # use Carp qw< carp >; $

Am I reading that right? It looks like it tells me that the carp call is on line 7, but it is really on line 3. If I make this hack to exports, it seems to give me the line number I expect:

sub ReportExportUse { my( $fh, @mods ) = @_; my( @exports, %export_mod, %conflict ); GroupExports( \( @exports, %export_mod, %conflict ), @mods ); my %mod_export; my $inuse = 0; if( @exports ) { my $match = MatchWords( @exports ); $match = qr/$match/; local $_; local $. = 0; # <------------- HACK while( <$fh> ) {

Here is my new output:

foo.pl: 3: carp('boo'); # This is line 3 carp # use Carp qw< carp >;

There is probably a better solution, and I suspect it has something to do with the seek.

Replies are listed 'Best First'.
Re^2: exports -- which module exports are used? ($.)
by tye (Sage) on Oct 03, 2013 at 17:08 UTC
    There is probably a better solution, and I suspect it has something to do with the seek.

    Indeed. This is how I've fixed it:

    $. = 0; seek $fh, 0, 0 or die "Can't rewind handle to $file: $!\n";

    (Updated: Actually, you also have to move that code so that it gets run before 'print' (for example) gets called, which is required else $. would be tied to STDOUT.)

    Alternately, you can do:

    { my $eof = <$fh>; $. = 0; } seek...

    Or I could just open the file twice.

    - tye        

      Thanks for the patch.