User Control Panel
Advertisements

HELP US, HELP YOU!

nested greps

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
jeffohrt
Newbie
Newbie


Joined: 08 May 2006
Posts: 17

Reputation: 6Reputation: 6Reputation: 6Reputation: 6Reputation: 6Reputation: 6

PostPosted: Mon Oct 23, 2006 2:47 pm    Post subject: nested greps Reply with quote

I have 120 Korean students progamming chatbots as the project phase of their conversation class ... I'm using RiveScript and some CGI ... I wrote a script that student by student ... summarizes their rscript files ... it just opens each file and reads the contents into an array ...

I'm using grep's to tally rscript features ... everything works ... I'm just wondering if there is a better way to write this one regex ... it's to count the number of atomic triggers and the only regex I can get to work looks like this ...


Code:
grep(!/\*+/, grep(/^\s*\+{1}/, @file))


Is there a better way to count the number of elements that start with 'x' and do not contain 'y' ...
Back to top
mattaustin
Sentinel
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Mon Oct 23, 2006 5:29 pm    Post subject: Reply with quote

You could do something like:

grep((/^x/ && $_ !~ /y/),@file);

or even look into "A zero-width negative lookahead assertion": (?!pattern)

_________________
[ matt ]
Back to top
jeffohrt
Newbie
Newbie


Joined: 08 May 2006
Posts: 17

Reputation: 6Reputation: 6Reputation: 6Reputation: 6Reputation: 6Reputation: 6

PostPosted: Wed Oct 25, 2006 12:14 pm    Post subject: Reply with quote

thanks ... I didn't realize grep took arguements similar to a map block ... your trick has tidied up quite a few of the uglier regex's I've got laying about ...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group