سؤال

I've begun to use ack because it seems to be a nice way to implement unix rgrep in a Perl script, easily. Thought, I use it through a Perl back-quoted system command:

# Searching for 'use' something 
my $pattern = "^use ";
my $path = "./path/to/libs/";
#Only pm files
my $parameters = "--perl";

my @uses = `ack $parameters $pattern $path`;

I know ack is pure Perl, but it seems to be designed for a command line use, not like an API or a Perl module. Is there a way to use it from a Perl script, I mean a module that makes possible to use ack like a Perl function :

# My phantasm
use ack;

my @uses = ack($parameters $pattern $path);

... or another method, timtowtdi.

هل كانت مفيدة؟

المحلول

You can't.

Maybe I should put "No user-serviceable parts inside" in the modules. It's really not meant for being used programatically. It really only uses modules for ease of maintainability for those working on it, and for ease of installing through the CPAN shell.

The file finding part is pretty simple to do. It's just calls to an iterator from File::Next.

Why do you want to call ack things from inside another Perl program? What's your use case?

Maybe this would be better taken up on the ack-users mailing list over on Google Groups.

نصائح أخرى

The module behind ack is App::Ack, but as you can see from the documentation, it's not really any kind of a programmatic interface at all, and not meant for public consumption. You could talk to Andy about making it better, but short of that you're probably best off using the commandline or re-inventing your own.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top