So, when you're looking for the date range, you can find the "Analysis Date Range", but then how do you decide what is the date coming after that?

I would say that you're looking for:

  1. First, the string "Analysis Date Range : " with an arbitrary amount of whitespace around the ':' (/Analysis Date Range\s+:\s+/)
  2. Then, at least one digit, which we want to remember (/([0-9]+)/)
  3. Then, a slash (which needs a backslash to escape it) followed by at least one digit, and record the digits but not the slash (/\/([0-9]+)/)
  4. Then, another slash followed by at least one digit, and again record the digits not the slash (/\/([0-9]+)/)
  5. And the rest doesn't matter
Combining that all into one:

# i modifer to make it case insensitive, just in case. if ($line =~ /Analysis Date Range\s*:\s*([0-9]+)\/([0-9]+)\/([0-9])+/i +) { print "I found an Analysis date with month/day $1, $2 in year $3\n"; }else{ print "This line did not have an analysis date that I recognize in i +t\n"; }

Another way to go, would be to grab larger chunks and then split them later:

  1. "Analysis Date Range : "
  2. Then a pile of digits-and-slashes (start date) ([0-9\/]+)
  3. Then whitespace and digits-and-colons (start time) \s([0-9:]+)
  4. Then more whitespace and some digits-and-slashes (end date)
  5. Finally, whitespace then digits-and-colons (end time)

PS: Is that date string "month day year" or "day month year"?


In reply to Re^3: Gettin certain lines of text from a text file! by SuicideJunkie
in thread Gettin certain lines of text from a text file! by Foxyirish1987

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.