While folloing perl hack book's example(chap 1 hack 5; it's about auto completion in vim and putting all modules in one file to search from), I found it very surprising that it wasn't working on my linux box
I am sure it was working somewhere else and I overlooked something, I digged in and see if I could make it work on my box

Finally results being at the bottom, and looking at the file that I created after running the script looks like it's working
Can some more experienced monks fix it so that I can see what I should have done instead of what I did?
My maine question is, when encountered below
## 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;
Looks like I could have gotten rid of directories more simpler way then applying 3 regex back to back to back?
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; }
so I changed to below and works but how I did it looks very inefficient..
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;

In reply to while following perl hack book by convenientstore

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.