Im trying to write a little program that searches for a word entered by a user. The program should run through the files, and if it finds that word,it backs up, reads in some text, and prints it for the user. Basically what google does i guess. My problem is, that when the thing finds the match, it seems to go to the end of the file before i can start working on it. Here is is what im doing.
if(m/$key/i)
{
$wordMatchFilePosition = tell FILEHANDLE;
seek FILEHANDLE, -1700, 1;
$currentFilePosition = tell FILEHANDLE;
...
So when it finds that term the user searched for (named key here) it does this filehandling stuff which moves the position back. But, like i said, it seems to wait until the file is at the end to start doing this stuff, because im getting all the end portions of text printed out, instead of where the word was located.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.