mIRC Homepage
Posted By: westor $read and $reade suggestion - 31/03/13 05:15 PM
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!
Posted By: hixxy Re: $read and $reade suggestion - 31/03/13 06:55 PM
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?
Posted By: westor Re: $read and $reade suggestion - 31/03/13 07:00 PM
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)
Posted By: hixxy Re: $read and $reade suggestion - 01/04/13 12:00 AM
$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.
Posted By: Riamus2 Re: $read and $reade suggestion - 01/04/13 01:12 AM
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.
Posted By: westor Re: $read and $reade suggestion - 01/04/13 12:50 PM
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!
Posted By: hixxy Re: $read and $reade suggestion - 01/04/13 01:54 PM
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
}
Posted By: westor Re: $read and $reade suggestion - 01/04/13 02:54 PM
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 !
Posted By: hixxy Re: $read and $reade suggestion - 01/04/13 02:56 PM
This already works! Try it smile
Posted By: westor Re: $read and $reade suggestion - 01/04/13 03:01 PM
I know, i've already talk about loops..
Posted By: hixxy Re: $read and $reade suggestion - 01/04/13 03:19 PM
So how do you think $reade should work? I don't understand...
Posted By: TRT Re: $read and $reade suggestion - 01/04/13 06:33 PM
He just wants to save a few bytes of code. laugh
Posted By: hixxy Re: $read and $reade suggestion - 01/04/13 07:49 PM
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!
Posted By: Wims Re: $read and $reade suggestion - 02/04/13 01:24 AM
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?
Posted By: westor Re: $read and $reade suggestion - 02/04/13 02:08 PM
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.
Posted By: Wims Re: $read and $reade suggestion - 02/04/13 03:25 PM
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.
Posted By: hixxy Re: $read and $reade suggestion - 02/04/13 08:29 PM
Now that we've established the suggested implementation it sounds good to me!
© mIRC Discussion Forums