Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Time and again I inherit code which does not use strict and warnings. One of the first things I do is turn on strict to see how much work lies ahead for me to make it strict. If I'm lucky, I just get a few complaints. More typically, however, I get screens full of output scrolling by. This will give you a short summary of the variables instead of the normal verbose strict output. For example:
$ strictv $card : 3 $cardcounter : 2 $count : 2 $counter : 3 $i : 5 $number : 2 $suit : 2 $types : 2 @alreadyused : 2 @cards : 6 @iterations : 2 @suit : 2 12 variables

It's also handy for code that people post on PerlMonks.

=head1 NAME B<strictv> - How (un)strict is your Perl code? =head1 SYNOPSIS strictv file ... =head1 DESCRIPTION Compile (but do not run) a Perl file using the C<strict> pragma. Only variables are checked. Input is a file (or several files). Output is to STDOUT. Example: strictv =cut use warnings FATAL => 'all'; use strict; use List::Util qw(max); use English qw(-no_match_vars); for my $file (@ARGV) { $CHILD_ERROR = 0; my @errs = qx(perl -Mstrict=vars -c $file 2>&1); if ($CHILD_ERROR) { my %var; for (@errs) { if (/open perl script/) { print; } elsif (/ "([^"]+)" /x) { $var{$1}++; } } if (%var) { my $width = max(map {length} keys %var); for my $name (sort keys %var) { printf " %-${width}s : %d\n", $name, $var{$name}; } print "$file: ", scalar(keys %var), " variables\n"; } } }

In reply to strictv -- how unstrict is your code? by toolic

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (2)
    As of 2015-11-30 02:49 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (756 votes), past polls