Hi zarath,

The first thing I would recommend is to use variable names that clearly state what they contain.

My first idea was perhaps to use unpack, but since you are saying that "these strings can be pretty much anything with any number of characters", that is probably not going to work.

Although this might sound paradoxical, the clearest and cleanest way to retrieve your data might be to use just a long regex using the constant strings as delimiters between the pieces you want to capture. Something like this (to be completed and tested):

my ($date, $file, $source_dir, $destination ...) = ($text =~ /(.{19}) +FATAL: Error while copying ([^ ]+?) from ([^ ]+?) to .../);

Update: when I started writing this answer, there was no other response, but it took me so long to write this answer that I finally posted a quarter of an hour later than Eily, and just said almost the same thing.

Update 2:: note that, the solution above is based on the data you've shown. I have assumed that the file and directory names you want to capture don't contain any space. If there can be spaces in your data to be captured, this would have to be slightly changed (thanks to Eily for pointing out the possibility that some of the data to be captured may contain spaces). Similarly, if the parts you want to capture may contain the strings "to" or "from", this might also be a problem. So you have to know very well your data in order to take your detailed decisions on how exactly to build your regex or regexes.


In reply to Re: Alternatives for index() ... substr() ? by Laurent_R
in thread Alternatives for index() ... substr() ? by zarath

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.