Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Check your CPAN modules for use vars

by usemodperl (Beadle)
on Jun 25, 2018 at 22:37 UTC ( [id://1217408]=CUFP: print w/replies, xml ) Need Help??

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Check your CPAN modules for use vars
by haukex (Archbishop) on Jun 26, 2018 at 10:17 UTC
    #!/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 # ######################################################

    I think you are misunderstanding the perldelta entry. It says (emphasis mine):

    The usage of use vars has been discouraged since the introduction of our in Perl 5.6.0. Where possible the usage of this pragma has now been removed from the Perl source code.

    vars is still very much present, just its usage by the Perl core has been removed. Note that the change is not listed in the "Incompatible Changes" section, and "Updated Modules and Pragmata" actually says "vars has been upgraded from version 1.03 to 1.04." See also:

    perl5/ $ git log --oneline --grep="use vars" v5.26.0..v5.28.0
    5069e57764 Update Filter::Util::Call to CPAN version 1.58
    1218f5ba79 Remove use vars from B::Deparse
    bc60657c80 configpm: fix duplicate 'our' declaration
    d8f3f638c2 [MERGE] Remove unnecessary use of 'use vars'
    9b78f2106b Document the removal of use vars from sources
    e64a0c479a Replace multiple 'use vars' by 'our' in regen.
    83461ff883 Replace multiple 'use vars' by 'our' in t
    3d3a0a8a5e Replace multiple 'use vars' by 'our' in utils
    fd55ca4fb1 Replace multiple 'use vars' by 'our' in ext
    cc01160e81 Replace multiple 'use vars' by 'our' in lib
    1a58b39af8 Replace multiple 'use vars' by 'our' in dist
    94d11354c7 fix a benchmarks sprintf entry

Re: Check your CPAN modules for use vars
by stevieb (Canon) on Jun 26, 2018 at 22:07 UTC

    It's been already confirmed that you "misunderstood" the perldelta entry regarding use vars;, I just want to throw a piece of advice to you...

    It is advantageous to use variable names that are descriptive of the function they are being used for. It is very difficult to comprehend code that is full of variables that are single-letter, other than those that are pretty much iteration-type variables (or single-char vars that are used in an extremely small/tight context, but I'd still recommend against it).

    $c, $n, $f, $m, $g... even in your small few-line code script there, it becomes a bit overwhelming.

    Extra keystrokes matter when writing code, and they are especially important when reading code a couple of days, months or years later.

    At least in Perl, we don't have to define everything with a type, such as const char* thing (c) or nonsense like List<Thing> thing = new List<Thing>() (c#). We can just do my $thing. The my and the full name of the variable are very useful.

      Completely agree. tchrist's Style Guide has this to say on the subject and includes this absolute gem from Dominus:

      The appropriate length of a name is directly proportional to the size of its scope.

      which, together with tchrist's philosophy that clarity trumps length (to which I also subscribe) I think sums it up nicely. It's also worth pointing out for completeness that such matters of style apply to any names in source: subs, packages, constants, variables, etc.

      It's fair to say that this advice is perfectly generic and applicable not just to Perl.

      Excellent advice as usual stevieb, thanks for reminding me. I refactored with your lesson in mind and recycled the code to extract comments (which are actually interesting). Hopefully this version is easier to read:
      #!/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"; }
      STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪
Re: Check your CPAN modules for use vars
by Anonymous Monk on Jun 25, 2018 at 23:19 UTC
    Because Perl 5.28.0 completely removes "use vars"

    no it hasnt, stop spreading FUD

      Seriously? Just misunderstood. Anyway slightly edited the description.
      STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪
        Seriously, yes. You do such a good job of posting and reposting FUD.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1217408]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found