convenientstore has asked for the wisdom of the Perl Monks concerning the following question:
Looks like I could have gotten rid of directories more simpler way then applying 3 regex back to back to back?## Need to get rid of directories, such as 5.8.8 or i386-l +inux-thread-multi ## 5.8.8::URI.pm ## i386-linux-thread-multi::Net::DNS::RR::MG.pm $file =~ s{^ +\d+\.\d+\.\d+::}{}g; $file =~ s{^ ?[^A-Z]+::}{}g; $file =~ s/^ +//g;
so I changed to below and works but how I did it looks very inefficient..use File::Find 'find'; # Where to create this list... my $LIST_DIR = "$ENV{HOME}/.vim_extras/" my $LIST_FILE = "file_that_lists_every_installed_Perl_module"; # Make sure the directory is available... unless (-e $LIST_DIR ) { mkdir $LIST_DIR or die "Couldn't create directory $LIST_DIR ($!)\\n"; } # (Re)create the file... open my $fh, '>', "$LIST_DIR$LIST_FILE" or die "Couldn't create file '$LIST_FILE' ($!)\\n"; # Only report each module once (the first time it's seen)... my %already_seen; # Walk through the module include directories, finding .pm files... for my $incl_dir (@INC) { find { wanted => sub { my $file = $_; # They have to end in .pm... return unless $file =~ /\\.pm\\z/; # Convert the path name to a module name... $file =~ s{^\\Q$incl_dir/\\E}{ }; $file =~ s{/}{::}g; $file =~ s{\\.pm\\z}{ }; # Handle standard subdirectories (like site_perl/ or 5.8.6 +/)... $file =~ s{^.*\\b[a-z_0-9]+::}{ }; $file =~ s{^\\d+\\.\\d+\\.\\d+::(?:[a-z_][a-z_0-9]*::)?}{ +}; return if $file =~ m{^::}; # Print the module's name (once)... print {$fh} $file, "\\n" unless $already_seen{$file}++; }, no_chdir => 1, }, $incl_dir; }
for my $incl_dir (@INC) { find { wanted => sub { my $file = $_; # They have to end in .pm... return unless $file =~ /.+\.pm/; # Convert the path name to a module name... $file =~ s{^\Q$incl_dir/\E}{ }; $file =~ s{/}{::}g; # Handle standard subdirectories (like site_perl/ or 5.8.6 +/)... ## 5.8.8::URI.pm ## i386-linux-thread-multi::Net::DNS::RR::MG.pm $file =~ s{^ +\d+\.\d+\.\d+::}{}g; $file =~ s{^ ?[^A-Z]+::}{}g; $file =~ s/^ +//g; return if $file =~ m{^::}; # Print the module's name (once)... #print "printing\n"; print {$fh} $file, "\n" unless $already_seen{$file}++; }, no_chdir => 1, }, $incl_dir;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: while following perl hack book
by Util (Priest) on Feb 04, 2008 at 04:28 UTC | |
by convenientstore (Pilgrim) on Feb 04, 2008 at 04:35 UTC | |
by ysth (Canon) on Feb 04, 2008 at 08:59 UTC | |
by convenientstore (Pilgrim) on Feb 04, 2008 at 20:04 UTC | |
by ysth (Canon) on Feb 04, 2008 at 20:11 UTC | |
by Util (Priest) on Feb 05, 2008 at 02:45 UTC | |
| |
by Util (Priest) on Feb 05, 2008 at 02:33 UTC |