Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl =pod Run this script from the perllib directory, where vendor_perl and site +_perl directories reside. (in my case it's /usr/lib/perl5) The script will output the modules (.pm files) located in both subdirs +. The branch (site_perl or vendor_perl) will be output for the older mod +ule (which you thus might want to remove). Set $PERLVERSION to whatever you have in both site_perl and vendor_per +l. =cut use strict; use warnings; my $PERLVERSION = '5.8.8'; # print each element of a list on a separate line $\ = $, = "\n"; my $s = 'site_perl'; my $v = 'vendor_perl'; my @pms = (); # takes a list of dirnames that are in both branches # returns a list of files that are in these dirs # in both branches (the branch prefix is truncated) sub common { my @dirs = @_; my @rv = (); for my $dir (@dirs) { my @site = glob("$s/$dir/*"); my @vendor = glob("$v/$dir/*"); s#^.*?/## for @site, @vendor; push @rv, grep {my $s = $_; grep {$_ eq $s} @vendor} @site; } return @rv; } # initialization # The array contains files that are in both branches # of one level of the subtree hierarchy. my @commons = common $PERLVERSION; # store the modules common to both branches. # Processes one level of subtree depth per iteration. while (@commons) { # store the modules - they will be output push @pms, grep {m/\.pm$/} @commons; # keep only directories for further traversal @commons = grep {-d "$s/$_"} @commons; # dive one level deeper @commons = common @commons; } # Print the found modules. # Try to figure out the version of each # and print the older one. # Don't print a branch if neither seems to be older. for my $pm (@pms) { # $spm -- site_perl PM # $vpm -- vendor_perl PM open my $spm, '<', "$s/$pm" or warn "Couldn't open $s/$pm"; open my $vpm, '<', "$v/$pm" or warn "Couldn't open $v/$pm"; # look for the version of each module # $sV -- site_perl module's VERSION # $vV -- vendor_perl module's VERSION no warnings 'uninitialized'; my ($sV) = grep /\$VERSION\s*=/, <$spm>; my ($vV) = grep /\$VERSION\s*=/, <$vpm>; $sV =~ /\$VERSION\s*=\D*([\d.]+)/; $sV = $1; $vV =~ /\$VERSION\s*=\D*([\d.]+)/; $vV = $1; my $leadstr = $sV > $vV ? "$v/" : $sV < $vV ? " $s/" : " " ; print $leadstr . $pm; }

In reply to Find doubly installed modules by Sixtease

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2023-03-21 10:16 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.