mIRC Home    About    Download    Register    News    Help

Print Thread
#241252 31/03/13 05:15 PM
Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Hello,

I wanna suggest something very usefull, as the $read has abillity to start reading from the BEGIN to END of the file, if there is anyway to add an $reade to start reading the file from the END to BEGIN.

- Thanks!


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
How would this work? $read(xyz,1) reads the first line. Are you saying $reade(xyz,1) should read the last line? $reade(xyz,2) should read the 2nd to last line.

Etc?

Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
I am trying to say that for example using $read(text.txt) it starts from the BEGGGING and get random item, i suggest something to start reading from the BOTTOM to the START of the file, eg: $reade(text.txt)


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
$read(text.txt) reads a random line, it doesn't start from the beginning or end.

I don't understand what you're asking for.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Random is random. It will be just as random regardless which way the file is read. About the only thing starting at the end might accomplish is if you want to search for text from the end instead of from the beginning. An example might be if you wanted to search a log file for the most recent time someone said something. I don't know how often someone would actually have need of that, though. And if we wanted to support something like that, a parameter would probably be far better than a new identifier.

Another improvement to $read that could go along with this is the ability to search from a given line in either direction. So if I want to find the first line up or down from line 50 that has "word" in it, you could use some parameter or something that will start the search at line 50 and search up or down based on your parameter for the word you're looking for. This can be useful in certain cases and would work well in combination with the ability to do a reverse search of a file.

I really don't see much need for either option, but I still see some value.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
I know the wildcards for $read, forget the random was my silly example, take my post to make an option in $read identifier to start reading the file from END to START , i post this because exists users that using this option and since now the only way is loop so why not an identifier with a simple option like (e) do this?

- Thanks!


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Right but how should it work; do you want it to work as I suggested in post #2?

Do you know you can just do this to read a file backwards:

Code:
var %i = $lines(file.txt)
while (%i) {
  ; do something with $read(file.txt,n,%i)
  dec %i
}

Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Originally Posted By: hixxy

Code:
var %i = $lines(file.txt)
while (%i) {
  ; do something with $read(file.txt,n,%i)
  dec %i
}


Like this exactly !


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
This already works! Try it smile

Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
I know, i've already talk about loops..


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
So how do you think $reade should work? I don't understand...

Joined: Jun 2003
Posts: 81
T
TRT Offline
Babel fish
Offline
Babel fish
T
Joined: Jun 2003
Posts: 81
He just wants to save a few bytes of code. laugh

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
What I'm trying to say is that he hasn't said what it should actually DO.

"read a file backwards" doesn't make a lot of sense because you can already do that with $read.

What would the format of the identifier actually be?

Does he mean it should iterate through a file and pass each line to a /command like $hfind(), $findfile() etc?

For example:

Code:
noop $reade(file.txt,n,echo -a $1-)


I think more details are needed!

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
As far as I understand him, he wants to be able to gives another switch to $read to change the way it reads: by reading from the end of the file (mirc currently reads from the beginning).
A very nice suggestion, but what about the N parameter? Assuming the switch is 'e' and the content of a file is:
Code:
a
mirc
b
c
e
f
mirc
g
h


would $read(file,e,2) look for the second line from the end? ("g" here)

$read(file,we,*mirc*,1) and then $readn, would $readn return 7 or 2?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2008
Posts: 1,515
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Yes, Wims that's one i mean.

in that : $read(file,we,*mirc*,1) and then $readn, would $readn return 7 or 2?

will return 7 because it starts reading for wildcard from the end of the file to start so if the wildcard of $read is in the text that starting reading with the 'e' parameter so will return in $readn the 7 line.


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Yeah, that looks like the ideal behavior for me too.

So the suggestion is about adding a new behavior to $read:
whenever $read starts looking for something from the beginning of the file (using the r/s/w switches with or without a line number N, or just the line number N), $read will now doing the search 'backward', starting from the end of the file.
The N parameter is also affected by the behavior, the line number N is relative from the end of the file.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Now that we've established the suggested implementation it sounds good to me!


Link Copied to Clipboard