Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: New to perl and regex

by Utilitarian (Vicar)
on Nov 19, 2012 at 08:44 UTC ( #1004484=note: print w/ replies, xml ) Need Help??


in reply to New to perl and regex

Neatened up your regular expressions a bit:

print "Enter a string (enter quit or [CTRL]-D to quit): "; while(<>) { $line = $_; last if ($_ =~ /^\s*quit\s*$/i); next if ($_ =~ /^\s~*$/); if($line =~ /\s*[a-zA-Z\s]+\s*-?\d+\s*/) { print $_; } }
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."


Comment on Re: New to perl and regex
Select or Download Code
Re^2: New to perl and regex
by rovf (Priest) on Nov 19, 2012 at 09:18 UTC

    I think it can be made even simpler than that:

    /[A-Za-z\s]+\s-?\d\d?/

    -- 
    Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004484]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2015-07-04 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls