CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
trying to use map or grep to remove 4 letter words

 



yatinhat
Novice

Oct 31, 2004, 2:58 PM

Post #1 of 2 (2747 views)
trying to use map or grep to remove 4 letter words Can't Post

I am trying to use 'map' or 'grep' to remove all four letter words from a list of words.

Here is my code:
Attachments: nofour.pl (85 B)


davorg
Thaumaturge / Moderator

Nov 1, 2004, 10:43 AM

Post #2 of 2 (2745 views)
Re: [yatinhat] trying to use map or grep to remove 4 letter words [In reply to] Can't Post

Your regex was invalid. Try this:

Code
@list = qw(one two three four); 
@nofour = grep {!/\b[a-z]{4}\b/} @list;
print "@nofour";


But it's probably easier without a regex

Code
my @list = qw(one two three four); 
my @nofour = grep { length != 4 } @list;
print "@nofour";


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives