"be consistent" | |
PerlMonks |
Remove all duplicates after regex captureby Maire (Scribe) |
on Aug 19, 2018 at 09:45 UTC ( [id://1220606]=perlquestion: print w/replies, xml ) | Need Help?? |
Maire has asked for the wisdom of the Perl Monks concerning the following question: Hello, Monks. I'm hoping that you can help me with what is probably quite a simple problem, but which is completely stumping me! I'm trying to work with text files which are fairly disorganized in terms of structure, and which have been stored in a hash. What I want from each file is to extract the line of text which begins "title:#" and ends with a "#" and store this text in a scalar to be used later. The problem arises because, within some of the text files, there are multiple lines which begin and end with "title#" and "#" respectively. What distinguishes the "titles" I want is that they only ever appear in each text file once, whereas the "titles" I do not want appear at least twice (but sometimes three or four times) in the same text file. So this is the basic script that I am using, which prints out all the titles The script above, obviously, prints out all 8 captured lines which begin with "title", but my desired output is:
I thought it might work to add a line in after the titles have been captured which (was supposed to!) remove all lines which appeared multiple times, but my attempts at this failed
I hope that makes sense: I have been working on this for about 9 hours now, so I'm a bit frazzled! Any help/pointers here would be very much appreciated! Thank you!
Back to
Seekers of Perl Wisdom
|
|