in reply to Re: searching a file, results into an array
in thread searching a file, results into an array

This topic is pretty well worked out, but want to add my 2bits: I like the list of lists of this solution over the hash method. The reason being that the list retains the sequence of records. I prefer a regular expression over a split in this type of format.. reason: there may be other tabs on the line. Since thare are no spaces in the filenames (in your example), I would use this
($filename,$description) = ($line =~ m/(^\S+)\s+(.*)/);
or as given in the referenced comment:
if($line =~ m/(^\S+)\s+(.*)/) { push @documents, [$1,$2]; }

Kinda of a "me too" comment; I know.

Replies are listed 'Best First'.
Re^3: searching a file, results into an array
by Random_Walk (Prior) on Oct 14, 2004 at 10:41 UTC

    Hi perlcapt

    The split I was using had the third parameter, (number of parts to split into) set to two. This prevents it eating any tabs beyond the first so any in the title are no problem. I think it has to remain the prefered option for efficiency as long as the file is all either blank lines or docs and tittles seperated by a tab.

    In my regex I included the litteral .DOC to improve rejection of spurrious lines though of course I am assuming no .XLS or .PPT files. I did make a couple of errors though...

    # I gave /^([\S]*.DOC)\t(.*)/ # the class grouping [] for \S is of course silly and # I forgot to escape the . in .DOC # this would have been better /^(\S*\.DOC)\t(.*)/

    Cheers,
    R.