The regex is rather simple for this but I think split would be even better (more efficient) if you are sure they will always be seperated by a first tab and any line with a first tab is valid. I put them into an array of arrays, more efficient than a hash keyed on doc if you only ever want to read through them sequentialy. Just another way to do it....

#!/usr/local/bin/perl -w use strict; my @documents; while (<DATA>) { # uncomment following line for the regex way # if (/^([\S]*.DOC)\t(.*)/) {push @documents, [$1, $2]} # uncomment these to use the split method # chomp; # next unless (my ($doc, $title)=split /\t/, $_, 2); # push @documents, [$doc, $title]; } print "I found the following docs\n\n"; foreach (@documents) { print "Doc: $_->[0] \t Title: $_->[1]\n"; } __DATA__ RS0029.DOC INTER UNIT HARNESS REQUIREMENT SPECIFICATION RS0036.DOC INSTRUMENT ELECTRONICS UNIT RS0037.DOC MECHANISM CONTROL ELECTRONICS RS0041.DOC IOU DESCAN MECHANISM RS0042.DOC IOU GENERIC MECHANISMS
Note the regex given is a bit more fussy than the obvious /(.*)\t(.*)/ which would cause you grief if the title contained a tab (if you don't know why read up about greedy pattern matching, it is very important)

Cheers,
R.


In reply to Re: searching a file, results into an array by Random_Walk
in thread searching a file, results into an array by Anonymous Monk

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.