PDA

View Full Version : Searching a file


parisa
10-31-03, 12:44 AM
Hi all

Can anyone tell me how to search through a file with tags and ignore the tags while searching??

The data are saved in a file called data.sgl and are stored like this.


code:--------------------------------------------------------------------------------
<ref>
<provnc>
<aulist>
<author> Bin Laden
</aulist>
<year>1990
<source> Cambridge University Press, Cambridge UK, 1st edition
<id>1
<keywords>
<key>terrorism
<key>whatever
</keywords>
</provnc>
<title> Terrorism
</ref>
--------------------------------------------------------------------------------


There are several entries like this in the file and the search script searches (eg: for a title) through the file and displays the matching info of the book.

Thanks

Chas
10-31-03, 01:42 PM
The regex below will give you a list of non-tag words in the doc that you can interate through:


my @new_data = $data =~ /[^<\/?\w+](\w+)/g;


That assumes that $data is the contents of your sgl file.

However, I think that you might be after something a little more complex, correct? Check out CPAN (http://search.cpan.org/) and see if you can find a SGML or a XML module (or a few perhaps) that will help you break down the data into useable data structures.

~Charlie