Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: ack 2.0 has been released (?wishlist?)

by Anonymous Monk
on Apr 29, 2013 at 07:31 UTC ( #1031174=note: print w/replies, xml ) Need Help??

in reply to ack 2.0 has been released

Fantastic, how can I call it from within my program?

Do you support something like the following?

my $iterator = App::Ack->fandango(qw[ -in dir1 dir2/dir3 --match ^the.$ ]); while(my $result = $iterator->() ){ ## my( $file, $lineno, $line ) = $result->finoli; ## my( $file, $lineno, $line ) = $result->fileNumberLine; my $file = $result->file; while( my( $lineno, $line ) = $result->next ){ print "$lineno: $line\n"; } }

Or how about ack()?

my @finolis = ack( qw[ --perl --match \bVERSION\b\s*=(.*?)$ ] ); for my $finoli ( @finolis ){ my( $file, $nolis ) = @$finoli; for my $noli ( @$nolis ){ my( $number, $line ) = @$noli; } }

Or --no-filename?  my @lines = ack( qw[ -h --perl --match sub\s+\w+ ]);

Or matches?  my @matches = ack( qw[ -o -h --perl --match sub\s+\K(\w+) ]);

Or  my @files = ack( qw[ -l --perl ], $dir1, $dir2, $dir3 );

Hmm, ??  my @files = ackfiles(qw[ --perl ], $dir1, $dir2 );
??  my @matches = ackmatches(qw[ --perl --match sub\s+\K(\w+) ]);
??  my @lines = acklines( qw[ --perl --match sub\s+\w+ ]);
??  ... = ackiterator(qw[ -in dir1 dir2/dir3 --match ^start.ends$ ]);

Hmm, i'm not sure about iterator :) but ackfiles/acklines/ackmatches seem like no-brainer-i-want-it feature, cause I've done that, ack ack ack some stuff, then write a File::Find::Rule loop to parse some files ... not exactly much harder to write, and ack() won't exactly shorten my effort that much, sure the file-type-matching logic will be the same, but I'm not sure if this would be useful

So, I've thought about it once or twice, might be nice, wouldn't take much effort to add-on this feature, but its not exactly a must-have, not sure it's really i-want-it, but I thought about wanting it on two occasions for about 5 seconds (honest)

Thanks for listening :)

Replies are listed 'Best First'.
Re^2: ack 2.0 has been released (?wishlist?)
by petdance (Parson) on Apr 29, 2013 at 14:18 UTC
    Do you have an actual use case for these? Or are you just imagining things that might possibly potentially be cool in the future maybe?


      Do you have an actual use case for these? Or are you just imagining things that might possibly potentially be cool in the future maybe?

      Um, what? That was it, that was my actual use case, use ack in a program for the same reason I'd use ack from the commandline , to get a list of files, or get a list of lines, or get a list of files and lines

      only the iterator portion inspired by File::Find::Rule/Iterator::Files iteration interfaces is a might-as-well-implement-it-if-you-re-implementing-it-thought-of-it-now

      The most important thing ack does that I can't do as trivially /easily myself already is all the filetype stuff
      sure it's easy to give find( qr/\.(pm|pl|pod|t)$/i ) for perl , i know perl, but what about --ruby? and others ...

      that's the killer feature ack has over grep, is simple/easy filetype/mimetype ... recognition with --perl --cpp ...

      Sure, I could cobble something together using MIME::Type/mmagic... and file::find,
      or I could shell-out to ack , which i've done , but then switched to file::find::Rule (shell is bleh)

      Have you seen File::Find seems grossly inefficient for performing simple file tasks??

      ack does a good job on the cli, the interface is compact , I know it already, no need for File::Find::Rule->oopy->verbosity or all find2perl reams-of-machine-generated-stuff or different-interfac

      compact interface for commandline? why not compact interface for commandline for our programs?

      Is it too obvious? Too useful?

        You do realize that ack's filetype detection is A) nothing at all related to MIME::Type, and B) entirely based on user-created rules, right? ack ships with sensible defaults, but they're still user-defined rules.

        If it's File::Find that you are fighting with, then why not take a look at File::Next, which is the underlying file-finding engine that ack uses?

        When I asked about use cases, I should have been more clear: Have you actually written code where you shell out to ack to get filenames? Or had it give you search results? What did you do with the search results then?

        Is it too obvious? Too useful?

        I don't understand what you're asking here.

        If you'd really like to get some traction on some sort of ack API, please go create a ticket in the GitHub issue tracker at


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031174]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2018-05-20 12:31 GMT
Find Nodes?
    Voting Booth?