Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I am putting the updated code up so you can all see how I got what I wanted.

#!/usr/bin/perl use strict; use warnings; use File::Find; use Data::Dumper; use Util::Line qw(line); my @files; sub wanted { my $file = $_ =~/.pm$/ ? $File::Find::name : undef; push @files, $file if $file; } my @directories = ('/home/me/Documents/'); find(\&wanted, @directories); my $module_directory = $directories[0].'www/files/lib/'; my @my_modules = map { my $file = $_; $file =~ s/$module_directory(.+) +\.pm/$1/; $file =~ s/\//::/g; $file; } @files; my $modules; for my $file (@files) { open my $fh, '<', $file or die "$file: $!"; my $file_convert = $file; $file_convert =~ s/$module_directory(.+)\.pm/$1/; $file_convert =~ s/\//::/g; while (my $line = <$fh>) { chomp($line); if ($line =~ s/^use ((:|\w)+)(.+)/$1/) { push @{$modules->{$file_convert}{'uses'}{'mine'}}, $1 if gr +ep(/$line/, @my_modules); # what modules the module uses push @{$modules->{$file_convert}{'uses'}{'not mine'}}, $1 if !gr +ep(/$line/, @my_modules); # what modules the module uses push @{$modules->{$1}{'used by'}}, $file_convert; # what modules + use this module } } } my $in = shift; my @ins = grep(/.*$in.*/, @my_modules); for (sort @ins) { my $mod = $modules->{$_}; line(0, $_); if ($mod->{'uses'}) { my $use = $mod->{'uses'}; line(1, "$_ uses"); if ($use->{'mine'}) { line(2, "My modules"); line(3, $_) for sort @{$use->{'mine'}}; } if ($use->{'not mine'}) { line(2, "Other modules"); line(3, $_) for @{$use->{'not mine'}}; } } if ($mod->{'used by'}) { line(1, "$_ used by"); line(2, $_) for sort @{$mod->{'used by'}}; } print "\n"; }

Here is example output.

Base::Data Base::Data uses My modules # it uses one of my modules Base::Path Other modules # it uses several modules that are not mine strict warnings Exporter File::Basename File::Spec List::Util Base::Data used by # it is used by all of these modules Base::LineMagic Base::Menu Base::Page HTML::Forms Movie People RolePlaying::AssetCost RolePlaying::Character::AbilityScores RolePlaying::Character::Class RolePlaying::Character::GameTable::Psionics RolePlaying::Character::GameTable::SpellProgression RolePlaying::Monster RolePlaying::Random::Weapon RolePlaying::Random::WildPsionics RolePlaying::SpellList RolePlaying::Spellbook RolePlaying::WordFind Util::ExternalLinks
No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to Re: Finding what modules use and what uses the modules by Lady_Aleena
in thread Finding what modules use and what uses the modules by Lady_Aleena

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (7)
    As of 2019-09-23 15:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The room is dark, and your next move is ...












      Results (280 votes). Check out past polls.

      Notices?