in reply to How to list all the installed perl modules

This will list all modules available in your search path.
perl -e 'while (<@INC>) { while (<$_/*.pm>) { print "$_\n"; } }'

-fuzzyping

Replies are listed 'Best First'.
Re: Re: How to list all the installed perl modules
by lestrrat (Deacon) on Mar 17, 2002 at 07:06 UTC

    uh, nope. your code doesn't account for the modules that live in the sub directories... For example, try finding File::Spec with your code.

    Probably best to stick to using File::Find to accomplish this job

Re: Re: How to list all the installed perl modules
by lordsuess (Scribe) on Mar 17, 2002 at 22:01 UTC
    I think this code would not find Modules in Subdirectories, e.g. Net::Telnet, so I'd prefer using something like the following:
    use File::Find; # Module list foreach my $dir (@INC){ find sub { print "$File::Find::name\t" if /\.pm$/; }, $dir; }
    or shorter:
    use File::Find; find sub { print "$File::Find::name\t" if /\.pm$/; }, @INC;
      Yeah, I realized that shortly thereafter. I've been picking my brain trying to figure out a way to do this with native functions, but I can't scale the recursion. Anyone else have any ideas? I've tried checking the input for (-d) and pushing it back to @INC, but my "while" doesn't seem to honor this attempt...
      perl -e 'while (<@INC>) { while (<$_/**>) { if (-d) { push(@INC,$_) } +elsif (/\.pm/) { print "$_\n" } else { next } } }'

      -fuzzyping
        while(<@INC>)
        Is very suspect code.... You probably want something like:
        my @copy = @INC; while(defined($_ = shift(@copy))) { # push to @copy as necessary }
        See Why is @array so slow? for more details.

        -Blake

        how about

        perl -e 'sub f{$d=pop;/\.pm/&&-f$_&&print"$_\n";-d$_&&f($_)for(<$d/*>) +}f($_)for@INC'