wana <> wrote:
> I am allowing a user to enter a perldoc name and I will run 'perldoc $name'
> for them.
>
> What regex will match all perldoc names but not allow for a command to be
> slipped into the name.
You won't need to solve that problem if you choose an approach
that does not require solving that problem.
If they can only look up the std docs, then build a lookup table
of the actual installed std docs, see code below.
Or maybe process the =head2 POD tags in perltoc.pod for legal names.
I think this ought to work though: /^(\w|:

+$/
(leaving out single quote on purpose since it is deprecated.)
---------------------------------
#!/usr/bin/perl
use warnings;
use strict;
foreach my $pod ( 'foo bar', qw/ perlnope perl perltoc perlfunc / ) {
if ( is_pod($pod) )
{ print "$pod is a POD\n" }
else
{ print "$pod is *not* a POD\n" }
}
BEGIN {
my %pods;
chomp( my $dir = qx/ perldoc -l perlfunc / );
$dir =~ s#/[^/]+$##; # should use File::Basename here...
opendir POD, $dir or die "could not open '$dir' directory $!";
$pods{ $_ } = 1 for map { s/.pod$// ? $_ : () } readdir POD;
closedir POD;
sub is_pod { exists $pods{ $_[0] } ? 1 : 0 }
}
---------------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas