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:
remove all non numbers from a list

 



yatinhat
Novice

Oct 31, 2004, 2:55 PM

Post #1 of 2 (2921 views)
remove all non numbers from a list Can't Post

I am trying to get a handle on the grep and map commands, but am stuck.

I am trying to remove all non-numbers from any list. Here is m code:

@nonnum = map /\D/, qw(one 2 3 four 5 6 7 8 nine);

print "@nonnum\n";


davorg
Thaumaturge / Moderator

Nov 1, 2004, 10:38 AM

Post #2 of 2 (2919 views)
Re: [yatinhat] remove all non numbers from a list [In reply to] Can't Post

This is a case where you need "grep" not "map".

Code
@nonnum = grep /\D/, qw(one 2 3 four 5 6 7 8 nine); 

print "@nonnum\n";


--
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