Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Split and Pattern Match

by djantzen (Priest)
on Jun 06, 2003 at 15:54 UTC ( [id://263734]=note: print w/replies, xml ) Need Help??


in reply to Split and Pattern Match

Does "1 word here another word" mean you have word pairs like "foo bar", "baz quux", or "foo bar baz quux"? Assuming the former, you can break that up like so:

my $var = "foo bar"; my @vals = split ' ', $var; # if you need something more complex, use +a regex for the pattern

Note that if you split on the whitespace it will already be stripped from the returned strings, so no extra processing should be necessary. For the second question, a match will do the trick:

foreach my $val (@vals) { print "Numeric\n" if $val =~ /^[0-9]{2}/; }

Alternatively you could use substr.


"The dead do not recognize context" -- Kai, Lexx

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-25 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found