Abhimanyu_Bhola [[EMAIL PROTECTED]] wrote:

> While reading the contents of a file, on a particular match, 
> I would like to start reading the file again from the line
> preceeding the match. (say, the match occured at line #45,
> I would like to start the file  reading from line #44)

Well, the easy way would of course be to cheat and
use an array as a cache for the previous lines. If
it is fixed in size and smallish, you might even
consider reading it in a single slurp, like i.e.
"my @lines = <IN>;"

> #1 I thought of making a copy of the filehandle(via & argument in open
> function) but that also doesn't solve the purpose as both of 
> them always point to the same location.Am I missing something here?

Now, this is like it is supposed to work. The handle is just
a handle, it doesn't carry any state.

> #2 Other option would be to open a secondary handle to the 
> same file and
> keep it one line before the main handle but his would mean an 
> overhead of managing an extra handle.

That's really a kludge. If caching all or some of the
lines is not an option, I'd use tell() keep track of
the current position and seek back to it when required.

MfG,
-- 
Thomas B�tzler, Network Engineer, Network Operations EMEA
Peregrine Systems GmbH             web: www.peregrine.com
Steinh�userstra�e 22             phone: +49-721-98143-166
D-76135 Karlsruhe / Germany        fax: +49-721-98143-196
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to