One of the reasons so many of us love Perl is how easy it is to hack out a quick utility that does exactly what we need. However, sharing these utilities doesn't always make sense because the utility is either custom to your needs (I had a precursor to Module::Starter which was dependent on my personal setup) or is so limited that posting it is sure to draw quick replies of "yeah, but that doesn't do X!"

So here's one of mine. I type subs PerlFileName and it dumps out a list of the subroutines. If I type subs -p PerlFileName it will include the "private" subs (those that begin with an underscore).

#!/usr/bin/perl use strict; use warnings; use Getopt::Long; GetOptions( "private" => \my $private ); my $file = shift or die "Usage: subs ProgramName"; my @subs; open my $fh, '<', $file or die "Cannot open ($file) for reading: $!"; while ( defined( my $line = <$fh> ) ) { if ( $line =~ /^\s*sub\s+([[:word:]]+)/ ) { my $sub = $1; next if ! $private && '_' eq substr $sub, 0, 1; push @subs, $sub; } } print join "\n", sort @subs;

It's pretty simple, will break on a lot of code and pretty much guarantees that posting it as a utility here won't meet with the best response. However, if I need a quick refresher on a module's interface, it's great. What private utilities do you have which might meet your needs but not be "general" enough to post elsewhere?

Cheers,
Ovid

New address of my CGI Course.


In reply to Private Utilities by Ovid

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.