Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Searching your code

by inblosam (Monk)
on Dec 14, 2004 at 18:22 UTC ( [id://414798]=perlquestion: print w/replies, xml ) Need Help??

inblosam has asked for the wisdom of the Perl Monks concerning the following question:

I tried a few different searches, but couldn't turn up anything that was really helpful for what I would like to do.

I have several good size websites with ~100+ pages of code each. I use Mason and it helps to manage things and reuse code, etc. But sometimes I want to find a certain piece of code, but have no idea where to find it, and don't want to look through dozens of files to locate it.

Is there some program or script or something that will index my scripts/pages and let me search, then show me the path to my file? I don't want to index my whole server, and I want it to be site specific so it would only entail the site's folder and cgi-bin. Any ideas??

I realize I could do this any number of ways myself, including some sort of grep function (I'm not so grep talented). But I want to limit it to a folder (and its subfolders)...

Hopefully I am not off of the beaten path topic-wise. I want to know what other people do.


Michael Jensen

Replies are listed 'Best First'.
Re: Searching your code
by zejames (Hermit) on Dec 14, 2004 at 18:32 UTC

    Did you have a look at ctags. It may be very useful for you, as it creates an index of language objects, and then help you to navigate through them with your favorite text editor (for example, it helps you finding a subroutine code when you see it called, even if it is defined anywhere else)

    For a simpler and more perlish specific tool, have a look at ptags.


    --
    zejames
Re: Searching your code
by mpeters (Chaplain) on Dec 14, 2004 at 18:37 UTC
    If you can use perl regular expressions then you can use grep. It's not fancy, but it's powerful and fairly easy. I think any other fancy tool you use will just complicate things.
    To search your project source files just
    $ cd /project/dir $ grep -R 'some_regex_to_look_for' -i .
    This will look recursively and case insensitively. I can't think of a better way to get more bang for your buck.
Re: Searching your code
by zentara (Archbishop) on Dec 14, 2004 at 18:41 UTC
    There is "Perlfect", and a couple of other indexers, and they work pretty well. The biggest problem is they index too much, and if you change settings to limit indexed words to greater than a certain length, you miss alot of keywords. Some allow you to limit recursion, use regexes, etc.

    Or check out alot of options at Freshmeat search

    Or google for "Building a Vector Space Search Engine in Perl"


    I'm not really a human, but I play one on earth. flash japh
Re: Searching your code
by trammell (Priest) on Dec 14, 2004 at 19:31 UTC
    I've never needed anything more involved than
    % find . -name '*.html' | xargs grep -2 'foo'
      Maybe a bit OT, but what does the -2 option mean ?
        Your grep may not support this option, but mine does (from man grep):
        -C [NUM], -NUM, --context[=NUM] Print NUM lines (default 2) of output context.
        In other words it prints some lines surrounding the match line. Very helpful when dealing with multi-line statements.
Re: Searching your code
by chb (Deacon) on Dec 15, 2004 at 07:25 UTC
    I have the following alias in my .shellrc:
    alias gri='find . -follow -print0 | xargs --null --max-args=1 grep --ignore-case --with-filename --line-number --directories=skip'
    this follows even symlinks (which grep -R does not, IIRC)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found