If the FROM field is the only real wild-card then be specific about what you do know, and relaxed about what you don't. By anchoring with specifics to the left and the right of the FROM field, you can relax your specification of that one field and still build a relatively robust regular expression:

while( my $line = <DATA> ) { print $line; chomp $line; my( $reqid, $dest, $from, $date, $time, $npages, $rcv ) = $line =~ m[ ^ # Beginning of input line. (\d+)\s+ # REQID (\w+)\s+ # DEST (\S.*?\S)\s+ # FROM (Accept non-space, anything [non- # greedily], non-space) (\d{1,2}/\d{1,2})\s+ # DATE (\d{1,2}:\d{1,2})\s+ # TIME (\d+)\s+ # nPages (\w+)\s* # RCV $ # End of input line. ]x; print "REQID: [$reqid]\tDEST: [$dest]\tFROM: [$from]\n"; print "DATE: [$date]\tTIME: [$time]\n"; print "nPages: [$npages]\tRCV: [$rcv]\n\n"; }

(I'm assuming that the fact your columns are not vertically aligned is not a typo; ie, that the fields aren't fixed length. If they are fixed length, this solution would be silly.)


Dave


In reply to Re: How to split line with varying number of tokens? by davido
in thread How to split line with varying number of tokens? by zBernie

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.