Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday August 19, 2007
01:49 PM

App::Pgrep 0.01 to the CPAN

[ #34153 ]

It's definitely alpha code, but I've just released App::Pgrep. This installs pgrep on your machine. It's a PPI-powered grep. It's alpha and has many things it cannot yet search for. Currently we can only search through quoted text, heredocs, comments and POD. More features will be added in the future.

NAME

pgrep - grep through Perl documents.

USAGE pgrep [options] [files or directory]

OPTIONS

Options which take arguments

-p, --pattern A Perl regular expression to match against. Default to the empty string. -s, --search What parts of the Perl document to search in. Defaults to C<--search quote,heredoc>.

Boolean options

-w, --warnings Enable warnings -l Filenames only -h, --help Display this help -?, Display this help -H, --man Longer manpage for prove

SEARCHES

The following parts of Perl documents may be searched for:

  • quote
  • Matches quoted strings (but not heredocs).

  • heredoc
  • Matches heredocs.

  • pod
  • Matches POD.

  • comment
  • Matches comments.

The --search argument can accept a comma separate list of items to search for:

--search pod,heredoc,quote

We'll add more things you can search for later.

All items may be plural to make them easier to read:

pgrep --search comments,heredocs --pattern 'XXX'

EXAMPLES

  • Quick 'n dirty SQL Injection attack scanner:
  • pgrep -pattern '^\s*(?i:select|insert|update|delete).*=\s*'?[\$\@]'

    Because we default to searching for 'quote' and 'heredoc' elements, the above searches them for things like:

    DELETE FROM table WHERE name='$name'

    Due to the nature of SQL injection attacks, the above is very limited. See http://www.perlmonks.org/ for more information.

  • Search for TODO items in comments
  • pgrep --search comments --pattern '(?i:XXX|TODO)' lib/

  • Search for TODO items in comments and POD
  • pgrep --search comments,pod --pattern '(?i:XXX|TODO)' lib/

  • Search for '=head3', only listing filenames
  • Older versions of Perl didn't recognize =head3 in POD. pgrep --search pod --pattern '^=head3' -l

NOTES

Default Directory

If --dir or --files are not supplied, assumes we're search from the current directory on down.

SEE ALSO

ack, included with App::Ack.

CAVEATS

This is alpha code. You've been warned.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • .. and the reason I'm interested in alternatives, is the option to specify file extensions (or more general: file name patterns) for the files to search in, specifically for recursive mode.

    grep depends on the shell to expand globs into a list of filenames, and this breaks down when your start descending into directories.
    • There's nothing wrong with grep. However, it's a different tool that attempts to satisfy a different need. I often want to search parts of a Perl document without searching all of it. Being able to search just through DATA sections or perhaps dump all regular expressions can be hand. You may have different needs. As time goes on, I'll be adding new features and it will be even more useful.

      Also, I was going to add file extension support, but I decided to put that off as "not needed" for the first iter

    • If you just need a smarter grep, without the ability to understand Perl, you might want something like ack.

  • Nice work, but the name 'pgrep' is not probably the best one since there's a conflict. [wikipedia.org]
    • Ah, crud. I hadn't heard of the command, so I didn't think to search for it. Thanks for the heads up. Recommendations welcome!

        • Hmm, that’s taken too. But ppgrep isn’t. Google only finds someone who uses that as their nickname and a page showing a Perl script called ppgrep that isn’t mentioned anywhere else.