Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: exports -- which module exports are used?

by toolic (Chancellor)
on Oct 03, 2013 at 14:41 UTC ( #1056765=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: exports -- which module exports are used?
Select or Download Code
Re^2: exports -- which module exports are used? ($.)
by tye (Cardinal) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-07-31 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls