Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

List EXE_FILES installed by CPAN

by usemodperl (Beadle)
on Jun 23, 2018 at 18:18 UTC ( [id://1217296]=CUFP: print w/replies, xml ) Need Help??

EDIT: The original node was buggy so here's a fixed version that seems to show all the executables installed by CPAN! Original node below so I can be embarrassed forever.☺

List EXE_FILES installed by CPAN:
#!/usr/bin/perl -l use strict; use warnings; # List EXE_FILES installed by CPAN $_ = join '', `perldoc -uT perllocal`; @_ = (/EXE_FILES:\s([^>]+)/sg); my @z = (); for (@_) { my @x = split /\s+/; s/^\S+\/// for @x; push @z, @x; } %_ = map { $_ => 1 } @z; print $_ for sort keys %_; #print scalar keys %_;
List EXE_FILES installed by CPAN, by module:
#!/usr/bin/perl -l use strict; use warnings; # List EXE_FILES installed by CPAN, by module $_ = join '', `perldoc -uT perllocal`; my @m = (/=head2.*?\|([^>]+)/g); my @e = (/EXE_FILES:\s([^>]*)/sg); for (my $c = 0; $c < scalar @m; $c++) { $_{$m[$c]} = $e[$c] } my @z = (); my $n = 0; for (sort { lc($a) cmp lc($b) } keys %_) { if (my @x = split /\s+/, $_{$_}) { print; $n += scalar @x; s/^\S+\/// for @x; print " $_" for @x; print ""; } } #print $n;
THE ORIGINAL NODE, DOES NOT WORK!:

List EXE_FILES installed by CPAN:
perl -le'chomp(@_=`perldoc -T perllocal`); # List EXE_FILES installed by CPAN $_=join"\n",@_;@_=split/\"Module\"\s/; @_=grep/EXE_FILES:\s[^"]+/,@_;for(@_){@x=split/\n/; @x=grep/EXE|0m/,@x;push@z,@x}s/^\s+\*\s+\"([^\"]+).?/$1/ for@z; @_=grep/EXE_FILES/,@z;@_=map{substr($_,11,length($_))}@_;undef@z; for(@_){if(/\s/){@x=split/\s/;push@z,$_ for@x}else{push@z,$_}} %_=map{s/^\S+\///;$_=>1}@z;print$_ for sort{lc($a)cmp lc($b)}keys%_'


List EXE_FILES installed by CPAN, by module:
perl -le'chomp(@_=`perldoc -T perllocal`); # List EXE_FILES installed by CPAN, by module $_=join"\n",@_; @_=split/\"Module\"\s/,$_; @_=grep/EXE_FILES:\s[^"]+/,@_;for(@_){@x=split/\n/; @x=grep/EXE_FILES|0m/,@x;push@z,@x}undef@x; s/^\s+\*\s+\"([^\"]+).?/$1/ for@z;my$m;for(@z){ if(/EXE_FILES:\s(.*)/){$_{$m}=$1}else{$m=$_;$_{$m}=1}} for(sort{lc($a)cmp lc($b)}keys %_){if($_{$_}=~/\s/){ @x=split/\s/,$_{$_};s/^\S+\/// for@x;$_{$_}=join"\n ", @x}else{$_{$_}=~s/^\S+\///g}print"$_\n $_{$_}\n"}'


STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪

Replies are listed 'Best First'.
Re: List EXE_FILES installed by CPAN
by jdporter (Chancellor) on Jun 24, 2018 at 01:17 UTC

    I'm kinda feeling this would be better in the Obfuscated Code section. :-/

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
      EDIT: This code is wrong, see OP for correct version! Sorry...

      I'm kinda feeling this would be better in the Obfuscated Code section. :-/

      I feel you. It was a struggle. Is there an easier way to list CPAN EXE_FILES? I know they could be easily grepped but I want formatting and proper sorting. Feel free to golf my code. I'm sure it could be even harder to understand, I mean more efficient and/or idiomatic. I just install these as scripts in a folder in my path for easy access.

      List EXE_FILES installed by CPAN:

      perl -le' chomp(@_=`perldoc -T perllocal`); # List EXE_FILES installed by CPAN $_=join"\n",@_; @_=split/\"Module\"\s/; @_=grep/EXE_FILES:\s[^"]+/,@_; for(@_){ @x=split/\n/; @x=grep/EXE|0m/,@x; push@z,@x } s/^\s+\*\s+\"([^\"]+).?/$1/ for@z; @_=grep/EXE_FILES/,@z; @_=map{substr($_,11,length($_))}@_; undef@z; for(@_){ if(/\s/){ @x=split/\s/; push@z,$_ for@x } else{ push@z,$_ } } %_=map{s/^\S+\///;$_=>1}@z; print$_ for sort{lc($a)cmp lc($b)}keys%_'


      List EXE_FILES installed by CPAN, by module:

      perl -le' chomp(@_=`perldoc -T perllocal`); # List EXE_FILES installed by CPAN, by module $_=join"\n",@_; @_=split/\"Module\"\s/,$_; @_=grep/EXE_FILES:\s[^"]+/,@_; for(@_){ @x=split/\n/; @x=grep/EXE_FILES|0m/,@x; push@z,@x } my$m; s/^\s+\*\s+\"([^\"]+).?/$1/ for@z; for(@z){ if(/EXE_FILES:\s(.*)/){ $_{$m}=$1 # wtf }else{ $m=$_;$_{$m}=1 # aha } } for(sort{lc($a)cmp lc($b)}keys%_){ if($_{$_}=~/\s/){ @x=split/\s/,$_{$_}; s/^\S+\/// for@x; $_{$_}=join"\n ",@x }else{ $_{$_}=~s/^\S+\///g } print"$_\n $_{$_}\n" }'


      STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪

        I'm kinda feeling this would be better in the Obfuscated Code section. :-/

        I feel you. It was a struggle. Is there an easier way to list CPAN EXE_FILES?

        Perl supports something new and weird, called a script. It's been around for just a few decades, so I understand you have never heard of it before. Essentially, you put your code into a text file instead of insisting to type half a kilobyte of code into the command line over and over again. Start the file with #! followed by the name of the interpreter, in your case /usr/bin/perl, followed by a newline. Put your code into the next lines. See also https://www.in-ulm.de/~mascheck/various/shebang/ and perlrun.

        The following quote comes from about the same time:

        "I don't comment my code because if it was hard to write, then it should also be hard to read."

        Sounds familiar? Yes, disk space and memory once were a scare resource. The MUMPS people learned that the hard way, and so their code typically looks like this, even after more than half of a century has passed:

        Q() N S,N,T,I,K,Q S I="K",S="11",K="l1",Q="R",T="K" I I=T D T Q:$Q Q Q T I I,S&K S S=S+K Q

        (Source: Wikipedia)

        Great news: We have increased disk space, memory and CPU power by several orders of magnitude since that dark age. You no longer have to fight for every byte. So feel free to add as much comments as you like, explaining whatever is not obvious in your code.

        Oh, and by the way: Some clever people invented something called POD, a way to create nice-looking documentation from a few lines of text inserted into your perl code. Other people have copied and extended that idea for other languages, at least twice (Javadoc, Doxygen).


        Well, actually, no REAL MUMPS programmer would ever use functions. "We have labels. We don't need no stinkin' functions." And the NEW command is something to avoid at all costs. "Adding scope to variables is for the weeks. We know our variables, and we know when we have to copy then to prevent overwriting." Plus, those lines are way too short. The first three lines should be combined into one. "Stuffing as much code into a line as possible makes the code run faster. The interpreter is line-based."

        (And no, I did not make up these quotes. They are real, from a time when I had to write MUMPS code for a living - in THIS century.)

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Feel free to golf my code.

        Ok.

        perl -MList::Util=uniq -le "$,=$/; print sort( uniq( qx(perldoc -uT pe +rllocal) =~ m(<EXE_FILES: (?:.*/)?(.*)>)g) );"

        Note, I'm not actually a golfer. This is just my idea of concise code.

        I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
Re: List EXE_FILES installed by CPAN
by choroba (Cardinal) on Jun 24, 2018 at 20:11 UTC
    Interestingly, the output on my machine is different to ls ~/perl5/bin which would be the way how I would proceed. It show several more executables.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Well /bin shows everything but this is just for CPAN executables. Anyway my original post was broken and was hiding about 60 programs from me! I also learned that unformatted code is very unpopular around here (outside obfu :-). This seems to work locally, let me know if you have any problems, or make improvements:

      List EXE_FILES installed by CPAN:
      #!/usr/bin/perl -l use strict; use warnings; # List EXE_FILES installed by CPAN $_ = join '', `perldoc -uT perllocal`; @_ = (/EXE_FILES:\s([^>]+)/sg); my @z = (); for (@_) { my @x = split /\s+/; s/^\S+\/// for @x; push @z, @x; } %_ = map { $_ => 1 } @z; print $_ for sort keys %_; #print scalar keys %_;
      List EXE_FILES installed by CPAN, by module:
      #!/usr/bin/perl -l use strict; use warnings; # List EXE_FILES installed by CPAN, by module $_ = join '', `perldoc -uT perllocal`; my @m = (/=head2.*?\|([^>]+)/g); my @e = (/EXE_FILES:\s([^>]*)/sg); for (my $c = 0; $c < scalar @m; $c++) { $_{$m[$c]} = $e[$c] } my @z = (); my $n = 0; for (sort { lc($a) cmp lc($b) } keys %_) { if (my @x = split /\s+/, $_{$_}) { print; $n += scalar @x; s/^\S+\/// for @x; print " $_" for @x; print ""; } } #print $n;
      STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!CPAN 🐪
        > Well /bin shows everything

        Well yes, but

        '~/perl5/bin' ne '/bin'

        In fact,

        $ echo $PERL_LOCAL_LIB_ROOT /home/choroba/perl5

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1217296]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-19 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found