mIRC Home    About    Download    Register    News    Help

Print Thread
#228857 12/01/11 06:37 PM
Joined: Jan 2009
Posts: 116
Knoeki Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Jan 2009
Posts: 116
Okay, this is doing my head in. I can't figure it out anymore.

What I want to do is the following:

1) set pointer to start of file
2) search the file to see if $+($2,*) already exists
3) if so, remove the line
4) set pointer to end of file
5) write $2- to file

I'm not even sure if #1 is needed, but yeah.

I sort of understand how it works, it's just that I can't figure out how to remove a line, and how to set the pointer to the end of the file..

And yes, I realize I could use regular /write, but I'm stubborn and want to use file handlers. :>


http://zowb.net

/server -m irc.p2p-network.net -j #zomgwtfbbq
(ssl on port 6697 and 7000)
Knoeki #228859 12/01/11 09:22 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I don't use file handling often, but I don't know of a file handling method of deleting a line. I mean, you could write every line after the found line up one line in the file, effectively deleting the line, but that's far from efficient. What's wrong with using /write? File handling has its uses and can definitely be better than /write, but that doesn't mean it's always the best solution to a problem.

Code:
alias Example {
  write -dw $+($2,*) temp.txt
  write temp.txt $2-
}


It really can't get much simpler than that.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #228861 12/01/11 10:24 PM
Joined: Jan 2009
Posts: 116
Knoeki Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Jan 2009
Posts: 116
From what I understand, file handling is faster. Consider that there's a really good chance I'll have to process several lines per second.

However, I've found that what I want to do with file handling, isn't going to be feasable. Or rather, it'll end up being way more complicated than needed.

Thanks for the reply anyway, it's much appreciated, but I'm going to consider a different method. (:


http://zowb.net

/server -m irc.p2p-network.net -j #zomgwtfbbq
(ssl on port 6697 and 7000)
Knoeki #228863 12/01/11 10:42 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
File handling is only faster if you need to perform more than one operation on the same file.

For example,

/write on its own would be faster than /fopen | /fwrite | /fclose, but if you need to do more than one /write on the same file, you'd be better off using file handling commands or /filter

However you need to consider when to open and close the file handle. If you don't close the file handle when mIRC exits (be it manually or because it crashed or something), there's a chance your file will be corrupted. This is why it's not really safe to keep a file handle open for too long; in case mIRC crashes.


Link Copied to Clipboard