Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Regex for non-patterned input

by Lawliet (Curate)
on Aug 15, 2013 at 11:13 UTC ( [id://1049554]=note: print w/replies, xml ) Need Help??


in reply to Regex for non-patterned input

Ah, so you cannot simply split on whitespace, because one of your columns has whitespace in it. Luckily, the data looks simple enough that we can get around that. For example, try the following (untested) regex:

for ( @wtodays ) { if (/^(\w+)\s+(\w+)\s+(\w+)\s+([\w\s]+)\s+(\w+)$/) { $table->addRow($1, $2, $3, $4, $5); } }

We individually capture each column. You can see that the regex for capturing the fourth column looks different than the others because of the whitespace it will contain. Specifically, instead of grabbing all the word-like characters, we grab all word-like and space-like characters, and then continue on our merry way to capturing the fifth column.

I hope this helps, and I hope you understand the logic behind it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found