Update:
I didnt notice line 4, whose format deviates from the other sample lines in that it doesnt have a monetary amount that i could discern. I think you'll need to provide a more specific explanation of the problem, including more analysis of the data that needs parsing.
Also, please, please, please, use some HTML tags to format your post
From your very brief explanation of what you're trying to due, it appears that your data lines have:
- some monetary indicator
- various info about the investment
- a due date
The monetary indicators are not identical, but my observation is that they are some indication of the units, i.e. pounds, dollars or euros, then the dollar amount and then a scale factor (mil or million) - im assuming others are valid.
The second column looks pretty free form, but after it should be the word 'due'. Is this always the case?
So, a regex something like this could work:
$line =~ /^( # start $1
\D+ # unit ind. (US$ for ex)
\d+(?:\.\d+)? # the amount
\s+ # whitespace
[A-Z]+ # scale (mil for ex)
) # end $1
(.+) # $2 - the second part
\sdue\s # literal word 'due' surrounded by spaces
(.+) # $3
$/xi;
my @columns = ($1, $2, $3)
Now keep in mind that your problem statement is rather ambiguous, but i think that this regex will work for the sample data you provided.
You'll probably have to add tweaks for various additional possibilities, such as commas in the numbers. This also assumes that the word 'due' does not appear anywhere in the data that should be in the second column.
Anyway, this should get you started. Note i did not test my code.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.