Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

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

    No recent polls found