Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Let's call the first file your search keys, and the second file, the values mapped to those search keys. Let's also assume that the mapping file is larger and more expensive to work with than the simple search key file. First, open and read your search key file into a hash, stripping away the > and newline characters (You might just capture m/^>(\w+:\w)/, for example). Each search key becomes a hash key. Go ahead and close your search key file but keep that hash. Second, open the mapping file for input, and an output file. For your mapping file set the input record separator (search perlvar for $/ for an explanation) to >, so that you're only dealing with complete records, and have no need of worrying about newlines. Now iterate over each record in the mapping file. chomp (removing the trailing >). Discard records that are empty (this takes care of the first >, for example). Then match m/^(\w+:\w)\n/, and use exists to check whether that key exists in your hash of search keys. If you've got a match, print to your output file the current record prepended with a '>'. That's one way to do it. When you get stuck in the actual code let us know which part is presenting difficulty. Filling in the rest of the blanks shouldn't be too much different from the solutions you obtained in some of your previous questions. Dave In reply to Re: print lines between a delimiter
by davido
|
|