Edit: Since no one likes my joke about use vars this node has been amended to a more useful version of the program:

#!/usr/bin/perl ################################## # Check installed *CPAN* modules for COMMENTS! # # Because CPAN modules have a lot of COMMENTS! # # https://perlmonks.org/index.pl?node_id=1217408 # ################################################## use strict; use warnings; use Config '%Config'; use ExtUtils::Installed; for (split $Config{path_sep}, $ENV{PATH}) { $|++ if -x "$_/grep" } die "you need grep" unless $|; my $time = time; my $perl = ExtUtils::Installed->new; my @cpan = $perl->modules(); my @temp = (); for (@cpan) { my @cpan = $perl->files($_); push @temp, @cpan; } @cpan = grep /site.*\.pm$/, @temp; my $opt = 0; if (@ARGV) { $opt = 1 } else { print qq~Checking CPAN modules for COMMENTS in Perl versio~. qq~n $^V\n(Invoke with any arg to skip questions and gener~. qq~ate a list of modules.)\n\n~; print qq~The list may be big and printing progress makes i~. qq~t a bit slower.\nDefault: display progress, format outp~. qq~ut and print offending lines of code.\nPress return to ~. qq~start or n for no progress and list output. y/N~; chomp($opt = <STDIN>); $opt = 1 if $opt and lc $opt eq 'n'; } my $INC = join '|', @INC; my $acme = 0; my $grep = 0; for my $cpan (@cpan) { print "\rChecking: ","$acme\tFound: $grep\t" unless $opt; if(@_ =`grep '^#' $cpan`) { @_ = grep !/^#(pod|[\-=~\*]|[#]{5,}|\s*\n)/,@_; # FAKE next unless scalar @_; (my $name = $cpan) =~ s/($INC)//; $name =~ s,^/,,; $name =~ s,/,::,g; $name =~ s/\.pm$//; s/^\s+/ / for @_; $_{$name} = join "\n ", @_; $grep++ } $acme++ } if ($opt) { print "$_\n" for sort keys %_ } else { $perl = scalar keys %_; $time = time - $time; print qq~$perl CPAN modules (out of $acme) found with COMMENTS!\n~; print "$_:\n $_{$_}","-"x60,"\n" for sort keys %_; print qq~$perl CPAN modules (out of $acme) found with COMMENTS!\n~; print "That took $time secs (grep searched ",sprintf("%0d",$perl/$t +ime), " modules/sec).\n"; }


ORIGINAL:

I heard the news today:

And had to find out how many modules are afflicted on my system (5.26.2):

905 CPAN modules (out of 4918) found with "use vars"!

Code for you:
#!/usr/bin/perl ###################################### # Check installed CPAN modules for use of "use vars" # # Because Perl 5.28.0 removes discouraged "use vars" # # https://perlmonks.org/index.pl?node_id=1217408 # ###################################################### use strict; use warnings; use autodie; use Config '%Config'; use ExtUtils::Installed; for (split $Config{path_sep}, $ENV{PATH}) { $|++ if -x "$_/grep" } die "you need grep" unless $|; my $t = time; my $m = ExtUtils::Installed->new; my @temp = $m->modules(); my @cpan = (); for (@temp) { my @x = $m->files($_); push @cpan, @x; } @cpan = grep /site.*\.pm$/, @cpan; my $opt = 0; if (@ARGV) { $opt = 1 } else { print qq~Checking CPAN modules for "use vars" in Perl version $^V ~. qq~(removed in Perl 5.28)\nhttps://metacpan.org/pod/release/XSAWYE~. qq~RX/perl-5.28.0/pod/perldelta.pod#Removal-of-use-vars \n(Invoke~. qq~ with any arg to skip questions and generate a list of modules.) \n +\n~; print qq~The list may be big and printing progress makes it a bit slow +er. Default: display progress, format output and print offending lines of code. Press return to start or n for no progress and list output. y/N~ +; chomp($opt = <STDIN>); $opt = 1 if $opt and lc $opt eq 'n'; } my $INC = join '|', @INC; my $n = 0; my $g = 0; for my $c (@cpan) { print "\rChecking: ","$n\tFound: $g\t" unless $opt; if (@_ = `grep 'use vars' $c`) { (my $f = $c) =~ s/($INC)//; $f =~ s,^/,,; $f =~ s,/,::,g; $f =~ s/\.pm$//; s/^\s+/ / for @_; $_{$f}=join"\n ",@_; $g++ } $n++ } if ($opt) { print "$_\n" for sort keys %_ } else { $m = scalar keys %_; $t = time - $t; print qq~$m CPAN modules (out of $n) found with "use vars"!\n~; print "$_:\n $_{$_}","-"x60,"\n" for sort keys %_; print qq~$m CPAN modules (out of $n) found with "use vars"!\n~; print "That took $t secs (grep searched ",sprintf("%0d",$m/$t), " modules/second).\n"; }
Output:

------------------------------------------------------------
XML::Twig:
 use vars qw($VERSION @ISA %valid_option);

 use vars qw( $weakrefs);

 use vars qw( %filter);
------------------------------------------------------------
XML::Twig::XPath:
 use vars qw($VERSION);
------------------------------------------------------------
YAPE::Regex:
 use vars '$VERSION';
------------------------------------------------------------
YAPE::Regex::Explain:
 use vars '$VERSION';
------------------------------------------------------------
905 CPAN modules  (out of 4918) found with "use vars"!
That took 31 secs (grep searched 29 modules/second).

STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪

In reply to Check your CPAN modules for use vars by usemodperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.