mIRC Home    About    Download    Register    News    Help

Print Thread
#166745 14/12/06 07:56 PM
Joined: Nov 2006
Posts: 6
R
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
R
Joined: Nov 2006
Posts: 6
I suggest adding a .line property to $read as the current method of getting the line number:

/noop $read(...)
<code using $readn>

can shorten many a script by a line.

RPGGamer #166757 14/12/06 09:32 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I'm unsure how this really shortens it by very much.

Code:
var %test = $iif($read(test.txt,s,word).line,$v1)
var %test = $iif($read(test.txt,s,word),$readn)


That's maybe not a great example, but both would put the line number into the variable.

What example do you have for it? Obviously, the first one (above) can be taken out of the $iif statement, but this lets it verify that there IS a matching line. Even taken out of the $iif statement, you shorten it by only 8 characters. And if you're reading through line-by-line and want to echo a line number, $readn is shorter than $read(test.txt,s,word).line anyhow.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #166830 15/12/06 03:56 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: Riamus2
I'm unsure how this really shortens it by very much.

Code:
var %test = $iif($read(test.txt,s,word).line,$v1)
var %test = $iif($read(test.txt,s,word),$readn)


That's maybe not a great example, but both would put the line number into the variable.


nah, not a great example indeed ;D $read with the 's' option returns everything except the search term, so if 'word' is on its own in the line $read(test.txt,s,word) returns $null which it would also return if no matching line was found

btw you could use something like var %test = $str($read(file,s,word),0) $readn or other identifiers that turn the result of $read() into $null


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #166863 15/12/06 10:26 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well... yes, I know what s does. People *do* use it when they know the line will start with the word/phrase. You can change that to w and use wildcards for those and it doesn't change the fact that the $readn one is still shorter in that particular example. Obviously, if they use s, they expect it to return $null if the word isn't found at the start of a line.

Btw, that $str example you gave doesn't really make much sense... $iif is a nicer (imo) way of handling it.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #166868 15/12/06 11:37 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
my point was the $iif method is broken, suppose the file contains "word" on its own on the line. $iif($read(file,s,word),$readn) returns $null, because that $read() returned $null

$str($read(file,s,word),0) simply turns that $read() to $null, but evaluates it so that $readn can be used.. so var %test = $str($read(file,s,word),0) $readn is an alternative to noop $read(file,s,word) | var %test = $readn


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #166869 15/12/06 11:45 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
With my example, $readn should also return $null... the variable should be $null if there isn't a match.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #166870 16/12/06 12:11 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
yes but it will also be $null if there IS a match! that's not desired behavior

the two /var lines you showed, the hypothetical $read().line and the other, would NOT be equivalent


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #166877 16/12/06 12:58 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
As I already stated, s would be used on purpose by someone who knows the match would start with that word and that they don't want something that has that word somewhere in the line or has just that word in the line. For the purpose of that example, it is correct.

If you wanted it to match wherever the word was, or if the word was the only thing in the line, then you would use a wildcard search, as I already said...

Code:
var %test = $iif($read(test.txt,w,*word*).line,$v1)
var %test = $iif($read(test.txt,w,*word*),$readn)


Let's see now...

This is a text file.
It has a word in it.
Line 2 is the one we want.

The first one will search for *word* and will find it in line 2 and with the .line property, $v1 will be the line number of the matching text... line 2. Agreed?

The second one will search for *word* and will find it in line 2. $readn will be the last line read... line 2. Agreed?

They both give the same results.

If all you are saying is that with s used, if a line has only that one word on it, that it won't be right... ok.... If a person CHOOSES to use s, then they better know how it works. There are reasons a person would WANT to see $null if the word was the only thing on the line. If they didn't want that, then they would use w to search instead.

But regardless, the code is correct for what it was intended. s may not be ideal for what one person might want and they might prefer w instead... for others, it might be exactly what they want.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #166878 16/12/06 01:12 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Using a wildcard search isn't always practical (if the search term has wildcard special characters in it), and there's a good chance the scripter wouldn't know whether the search term would match the line partially or entirely.

This is getting off-topic from the original feature suggestion now though. The point is that a .line property has a valid use and, although we all know it can be scripted, it's probably worth being built-in aswell.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Riamus2 #166879 16/12/06 01:15 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
mk i was just under the impression you were suggesting a general scripted workaround for his proposed $read().line, instead of a purpose specific one :F after all, thats the only circumstance under which i'd make a comparison on the size of the two methods.. ie. if they both did the same exact thing



"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
jaytea #166882 16/12/06 01:25 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
They both *would* do the same thing. Look at the wildcard example. Do you disagree that they would both produce the same output?

In the s example, they would also produce the same output unless .line property does something different with a line that only has the search parameter than what current $read does with it using the s parameter. Perhaps, $read(text.txt,s,word).line will give a line number for a line holding only that word and $readn wouldn't. That's not guaranteed because it's not implemented yet. If that is the case, then ok... it isn't exactly the same in that ONE situation. However, wildcard searching would be the same. So would s searching as long as no line has just the matchtext. In any case, this was meant as a general example to show comparisons of the line length and to point out that I don't see how the use of .line will save much space over current methods.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #166884 16/12/06 01:37 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
Perhaps, $read(text.txt,s,word).line will give a line number for a line holding only that word and $readn wouldn't. That's not guaranteed because it's not implemented yet.

- I don't think you understand how $read(,s,) and $readn work. When a search term matches a line exactly, the $read() call will return nothing since there's nothing after the search term, however $readn will correctly return the value of the line matched. That's why your two examples aren't the same and one reason why a $read().line property would be handy in some situations.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Actually, I do see a problem with it thanks to how I used $iif for the example (I'm trying to do this while finishing up stuff at work, so didn't take into account all situations... the wildcard example does work). The way I worded what you quoted is still correct. The $readn example would not give an output because the $iif check would be false ($null). The .line example would give a line number because the .line check would be true (a line number) assuming that it will give a line number regardless of whether there is text after the matchtext, which is what would make sense to me if it was implemented.

So use my wildcard example as the reason why I don't see much difference in length. Or, just show me an example that shows how the change in length is significant when using .line instead of $readn as obviously, this is just ONE example and other situations will change the code and the lengths for both methods.

This would actually do what was necessary if using $iif ... just needed the check for the false that would show up if the matchtext was all that was on that line.
Code:
$iif($read(text.txt,s,word).line,$v1)
$iif($read(text.txt,s,word),$readn,$iif($readn,$v1))


So that example is 15 characters shorter. Unless you use this regularly, that isn't a significant reduction in characters, and the wildcard example is more likely to be used, which has an increase in characters. I just don't see that much difference.

I actually don't care if it is added... I just don't see the need.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard