Just a few nits ;-)
From: "Hanson, Rob" <[EMAIL PROTECTED]>
> I think there is something like that, but I'm not sure. In the past I
> have rolled my own like this...
>
> #!/usr/bin/perl
>
> use File::Find;
>
> my $dir = '';
>
> for (@INC) {
> $dir = $_;
> find (\&wanted, $dir);
> }
>
> sub wanted {
> next unless /\.pm$/;
> my $file = $File::Find::name;
>
> $file =~ s/\Q$dir//; # remove dir path
> $file =~ s|^[/\\]||; # remove leading slash
These two can be replaced by
$file =~ s{\Q$dir\E[/\\]}{};
> $file =~ s/\.pm//; # remove .pm
This one should be
$file =~ s/\.pm$//; # remove .pm
or
substr( $file, -3) = '';
# replace the last three characters with nothing
> $file =~ s|[/\\]|::|g; # convert slash to ::
>
> print "$file\n"; # print module name
> }
You actually don't need to use the regexp to remove the directory.
You can do it like this:
#!/usr/bin/perl
use File::Find;
my $dir_len;
for (@INC) {
$dir_len = length($_)+1;
find (\&wanted, $_);
}
sub wanted {
next unless /\.pm$/;
my $file = $File::Find::name;
substr( $file, 0, $dir_len) = '';
substr( $file, -3) = '';
$file =~ s|[/\\]|::|g; # convert slash to ::
print "$file\n"; # print module name
}
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]