The following code shows one way of doing what you want:
(For convenience, I put the list of files in the code's __DATA__ section, but you'll read them from a separate file.)#!/usr/bin/perl use warnings; use strict; # read the files into a hash of ( filename => title ) my %files; while (<DATA>) { chomp; # get rid of line-ending if (my ($file, $title) = split ' ', $_, 2) { $files{$file} = $title; } } # print out the files in our hash, sorted by file name foreach my $file (sort keys %files) { my $title = $files{$file}; print "$file = $title\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
The only tricky part is our split invocation, which says, "split lines on whitespace into two parts." If we're successful in splitting the current line, we get back the filename and its title, which we store in the variables $file and $title respectively. These, in turn, we store in a hash called, appropriately enough, %files.
The foreach loop shows how to read values out of the hash. I just print them out, but I trust that you can convert each into the appropraite hypertext link. Here's the code's output:
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
Cheers,
Tom
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
In reply to Re: searching a file, results into an array
by tmoertel
in thread searching a file, results into an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |