http://qs1969.pair.com?node_id=513033

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.