From WikiChip
Editing mirc/identifiers/$read

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 33: Line 33:
 
== Examples ==
 
== Examples ==
 
<source lang="mIRC">
 
<source lang="mIRC">
//echo -a prev line read was $readn - $read(versions.txt,nt) is line $readn
+
//echo -a line $readn is $read(versions.txt,nt)
 
returns: a random line from versions.txt even if it is $null
 
returns: a random line from versions.txt even if it is $null
 
Note: You can use $read(quotes.txt,nt) as your quit message, and it will display a random line from that file when you /quit a server.
 
Note: You can use $read(quotes.txt,nt) as your quit message, and it will display a random line from that file when you /quit a server.
 
If you don't use the 'n' switch, and if $read(quotes.txt) randomly chooses the line created by the following command, it will evaluate the identifiers using their current values.
 
 
//write quotes.txt Banned from $ $+ network until $ $+ gmt($ $+ calc($ $+ ctime +86400*7)) GMT
 
  
 
//echo -a $read(versions.txt,nt,3)
 
//echo -a $read(versions.txt,nt,3)
returns: contents of line #3
+
returns: line #3
 
//echo -a $read(versions.txt,nt,2)
 
//echo -a $read(versions.txt,nt,2)
returns: contents of line #2. if the line is blank (length = 0), returns $null
+
returns: line #2. if the line length is blank (length = 0), returns $null
  
 
//echo -a $read(versions.txt,nt,invalid)
 
//echo -a $read(versions.txt,nt,invalid)
 
returns: If s/r/w switches not used and 3rd parameter is used without being a number >= 1, returns line #1.
 
returns: If s/r/w switches not used and 3rd parameter is used without being a number >= 1, returns line #1.
  
//echo -a $read(file.txt,t,3)
+
//echo -a $read(file.txt,t,4)
returns: Contents of line#3. Because the 'n' switch wasn't used, evaluates any $identifiers and %variables instead of returning strings beginning with "$" or "%".
+
returns: Contents of line#3. Because the 'n' switch wasn't used, evaluates any identifiers instead of returning strings beginning with "S".
  
//echo -a $read(file.txt,tp,3)
+
//echo -a $read(file.txt,tp,4)
 
returns: Same, except if the line contains the | "pipe" symbol, that is treated as a command separator, and the portion beyond the pipe is executed as if a script command.
 
returns: Same, except if the line contains the | "pipe" symbol, that is treated as a command separator, and the portion beyond the pipe is executed as if a script command.
  
Line 60: Line 56:
 
//echo -a $read(versions.txt,nts,10.fixed,200) line: $readn
 
//echo -a $read(versions.txt,nts,10.fixed,200) line: $readn
 
matches: Same, except begins scanning at line 200.
 
matches: Same, except begins scanning at line 200.
 
//echo -a $read(versions.txt,nts,3.Changed udpate) line: $readn
 
Uses matchtext containing spaces
 
  
 
//echo -a $read(versions.txt,nts,changes:) $readn  
 
//echo -a $read(versions.txt,nts,changes:) $readn  
Line 79: Line 72:
 
returns first line containing exactly 3 space-tokenized 'words'.
 
returns first line containing exactly 3 space-tokenized 'words'.
  
Return all matches in file after ensuring $readn is zero:
+
//var %i 1 | :label | echo -ag $read(versions.txt,ntw,* - mirc*,%i) $readn | var %i = 1 + $readn | if ($readn) goto label
//var %i 1 | var %a $read(set readn to zero,nt) | while ($read(versions.txt,ntw,*- mIRC v*,$calc(1+$readn))) { echo -a $ord(%i) match: $v1 | inc %i }
+
returns all lines of the file matching the matchtext
  
 
//write -c test.dat top line | var %i 2 | while (%i isnum 2-100) { write test.dat line %i | inc %i }
 
//write -c test.dat top line | var %i 2 | while (%i isnum 2-100) { write test.dat line %i | inc %i }
This creates a 100-line file, where the 1st line says "top line" and lines 2-99 are that same number.
+
This creates a 100-line file, where the 1st line says "top line" and lines 2-99 show their line number.
  
//write -l1 test.dat top | echo -a $read(test.dat,n) is the contents of line $readn
+
//write -l1 test.dat top | echo -a $read(test.dat,n)
 
Because Line#1 is not a number, mIRC does not treat it as a line count for the file, so this returns a random line from the text file.
 
Because Line#1 is not a number, mIRC does not treat it as a line count for the file, so this returns a random line from the text file.
  
//write -l1 test.dat  40 | echo -a $read(test.dat,n) is the contents of line $readn
+
//write -l1 test.dat  40 | echo -a $read(test.dat,n) $readn
Now that line#1 is the number N, returns a random line from physical line 2 through N+1 as if they're lines 1-N, so it's possible for this to return $readn 1-40 when reading from lines 2-41. As long as line 1 is the number 40, reading a random line without using the 't' switch never returns a $readn value greater than 40
+
Now that line#1 is a number, returns a random line from line 2 through N+1, so it's possible for this to return $readn 1-40 when reading from lines 2-41.
 +
//write -c test.dat 40 | write test.dat test2 | echo -a with n: $read(test.dat,n,0) . $readn without n: $read(test.dat,0) $readn
  
 
//var %pattern \d{5,} | echo -a $read(versions.txt,ntr,%pattern) $readn
 
//var %pattern \d{5,} | echo -a $read(versions.txt,ntr,%pattern) $readn
'r' switch indicates matchtext is a regex pattern. Returns: first line containing at least 5 consecutive number digits. Regex defaults to case-sensitive unless the 'i' flag is used.
+
'r' switch indicates matchtext is a regex pattern. Returns: first line containing at least 5 consecutive number digits
 
 
 
 
First line containing the string 'wildcard' anywhere:
 
//echo -a $read(versions.txt,ntw,*wildcard*) line: $readn
 
First line containing the string 'wildcard' anywhere on/after line 2000:
 
//echo -a $read(versions.txt,ntw,*wildcard*,2000) line: $readn
 
 
 
Shows line 1 being evaluated, including a local %variable created after the disk write:
 
//write -l1 test.txt $ $+ me % $+ a | var %a $asctime | echo -a $read(test.txt,n,1) vs $read(test.txt,1)
 
 
 
quirk: if attempting to read from a non-existent line, $readn is set to 1 more than the number of lines even though it did not successfully read anything.
 
//write -cl1 test.txt 5 | write -l2 test.txt test2 | write -l3 test.txt test3 | echo -a text: $read(test.txt,nt,44) readn: $readn
 
the above returns 4 even though there are only 3 lines. If the 't' switch is removed, where $read treats the 2nd and 3rd lines as lines 1 and 2 due to the numeric line1, it returns the non-existent line 3.
 
 
 
quirk: if the numeric line 1 is greater than the number of lines, and $read attempts to return a random line from the file, it sets $readn to the first non-existent line number. In this example, the numeric 10 causes $readn to be 1 or 2 a combined 20% of the time, and $readn is 3 the other 80% time when it returns $null text
 
//write -cl1 test.txt 10 | write -l2 test.txt test2 | write -l3 test.txt test3 | echo -a text: $read(test.txt,n) readn: $readn
 
 
 
quirk: where line1 is numeric. line 0 is supposed to return the number, but that doesn't happen when 'n' switch is used by itself.
 
//write -c test.dat 40 | write test.dat test2 | echo -a with n: $read(test.dat,n,0) and readn= $readn without n: $read(test.dat,0) and readn= $readn
 
 
 
This shows how $read identifies what defines a line:
 
//clipboard $cr $+ 1 $+ $lf $+ 2 $+ $crlf $+ 3 $+ $cr $+ $crlf $+ 4 $+ $crlf $+ $lf $+ 5 $+ $lf $+ $cr $+ 6 $+ $cr $+ 7 | noop $regsubex(foo,$cb,,,&var) | bwrite -c test.dat 0 -1 &var | var %i $lines(test.dat) | echo -a cb(0) $cb(0) vs lines(test.dat) %i | while (%i) { noop $cb(%i,,&v2) | echo -a %i : clipboard: $bvar(&v2,1-) : $bvar(&v2,1-).text vs $ $+ read: $read(test.dat,nt,%i) | dec %i }
 
 
 
Every $cr and every $lf  are seen as a line-ending, except for 1 $cr immediately preceding a $lf causing it to be seen as part of a $crlf. The End-of-File is also another line ending if the file does not end with a $cr or $lf
 
 
</source>
 
</source>
 
 
== Compatibility ==
 
== Compatibility ==
 
For modern documented syntax:
 
For modern documented syntax:

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)