Thread: grep() command?

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0


    what is this command in Perl?
    what does it do?

    i was just wondering what it did, as I am using it in a CGI, but am not sure exactly what it does.

    any info on this at all would be appreciated. if you need more info, please let me know.


    CujoRbd


  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    300
    Rep Power
    14
    Well, its not that easy to explain grep() or map() functions in Perl. The Perl Archive has a really cool article that deals with grep at:

    http://tlc.perlarchive.com/0008/01.shtml

    Basically, the grep() functions uses regular expressions to make a list out of another list. This is a somewhat blunt explanation, so you should really go and read the article.

    HTH.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0


    thanks! that answered alot of my questions.

    to explain further what i am doing, i am basically adapting an old script of mine, but don't remember why I had put in the 'grep()' command. with that page you gave me, i figured out that i must've put it in to count the amount of users i have under a specific list.

    though this answers my question, it now brings up another one.

    i am trying to basically get a printout of every user, along with some info within their specified user file.

    the grep command i had there was this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    @members = grep(/.cgi/, @members);[/code]

    which had just sprung off of this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    opendir (MEMBERDIR, "$MembersPath");
    @members = readdir(MEMBERDIR);
    closedir (MEMBERDIR);[/code]

    so, basically i've opened up a certain directory and counted the amount of files that end in "cgi" (or the amount of users that are there, to be more specific).

    what i was hoping to do for this was to add a "foreach" statement and basically print out each user's info. but as the grep counts files and doesn't really distinguish between them, i'm not really sure what to do.

    what can i do instead then? is there a certain function/command that i should use? or what?

    please help me here, as I'd really like to finally get this script complete.


    THANKS!!!


    Cujo


  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0
    ^^^

IMN logo majestic logo threadwatch logo seochat tools logo