I have a txt file as an input.
It is a list which looks like this:
A12345
B153875
C34893
...
...
and I have a database file which looks like this:
A12345 detail information
nvonafwenfovosdncsjdnfoewhuwerhwieufhiudhfisdfnsd
sdofnowerugfeuhgfurhgiuwerhfjdshfiasdhifheruwufhi
irgfiweurgf
A246 detail information
isdofnowerugfeuhgfurhgiuwerhfjdshfiadhifheruwufhi
wgerjgneiguihuhdnvkjdnvkjbdegiauberiubgieubgridfb
ooogrngoawerngiauengugbuivrug
B153875 detail information
wgerjgneiguihuvkwwjddnvkegtiaugberijubgieubgridfb
eragnowergnoweungfiousdhiuhsdnjkfnsk
C34893 detail information
fnweuraiwerbgivjbdbvurgfuwherugtheurhguhweriguhdg
sdgnasoughiueghaiwuh
...
...
...
My goal now is to find all the names listed (A12345_XXX, B153875_XXX, C34893_XXX, ...etc) in the database and create an output file like this (containing the names and the contents):
A12345_XXX
nvonafwenfovosdncsjdnfoewhuwerhwieufhiudhfisdfnsd
sdofnowerugfeuhgfurhgiuwerhfjdshfiasdhifheruwufhi
irgfiweurgf
B153875_XXX
wgerjgneiguihuvkwwjddnvkegtiaugberijubgieubgridfb
eragnowergnoweungfiousdhiuhsdnjkfnsk
C34893_XXX
fnweuraiwerbgivjbdbvurgfuwherugtheurhguhweriguhdg
sdgnasoughiueghaiwuh
...
...
How should I approach this?
(Fortunately, both the namelist and the database are in alphabetical order.)
My code so far only cover the filehandle part, something like this:
($v1, $v2, $v3) = @ARGV;
//$v1 is the namelist file
//$v2 is the database filename
//$v3 is the desired output filename
open (FILEHANDLE, $v1) || die;
open (DATABASE, $v2) || die;
open (RESULTS, ">$v2");
......
......
......
close (FILEHANDLE);
close (DATABASE);
close (RESULTS);
exit;
Request help!