mIRC Home    About    Download    Register    News    Help

Print Thread
$read and $reade suggestion #241252 31/03/13 05:15 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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!

Re: $read and $reade suggestion [Re: westor] #241258 31/03/13 06:55 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
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?

Re: $read and $reade suggestion [Re: hixxy] #241259 31/03/13 07:00 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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)

Re: $read and $reade suggestion [Re: westor] #241262 01/04/13 12:00 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
$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.

Re: $read and $reade suggestion [Re: westor] #241263 01/04/13 01:12 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: $read and $reade suggestion [Re: Riamus2] #241266 01/04/13 12:50 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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!

Re: $read and $reade suggestion [Re: westor] #241268 01/04/13 01:54 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
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
}

Re: $read and $reade suggestion [Re: hixxy] #241269 01/04/13 02:54 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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 !

Re: $read and $reade suggestion [Re: westor] #241270 01/04/13 02:56 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
This already works! Try it smile

Re: $read and $reade suggestion [Re: hixxy] #241271 01/04/13 03:01 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
I know, i've already talk about loops..

Re: $read and $reade suggestion [Re: westor] #241272 01/04/13 03:19 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
So how do you think $reade should work? I don't understand...

Re: $read and $reade suggestion [Re: hixxy] #241273 01/04/13 06:33 PM
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

Re: $read and $reade suggestion [Re: TRT] #241274 01/04/13 07:49 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
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!

Re: $read and $reade suggestion [Re: hixxy] #241276 02/04/13 01:24 AM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
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?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $read and $reade suggestion [Re: Wims] #241277 02/04/13 02:08 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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.

Re: $read and $reade suggestion [Re: westor] #241280 02/04/13 03:25 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $read and $reade suggestion [Re: westor] #241281 02/04/13 08:29 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
Now that we've established the suggested implementation it sounds good to me!