|
1 | 1 | # NQP Built-in Subs List
|
2 | 2 |
|
3 |
| -The following subroutines are available to use in ```nqp``` programs. |
4 |
| -They are described in ```nqp/src/core``` modules. |
| 3 | +The following subroutines are available to use in `nqp` programs. |
| 4 | +They are described in `nqp/src/core` modules. |
5 | 5 |
|
6 |
| -# From ```nqp/src/core/Regex.nqp``` |
| 6 | +# From `nqp/src/core/Regex.nqp` |
7 | 7 |
|
8 | 8 | ## match
|
9 |
| -* `match($text, $regex, :$global?)` |
| 9 | +* `match($text, $regex, :$global? --> @array)` |
10 | 10 |
|
11 |
| -Match ```$text``` against ```$regex```. If the ```$global``` flag is |
| 11 | +Match `$text` against `$regex`. If the `$global` flag is |
12 | 12 | given, then return an array of all non-overlapping matches.
|
13 | 13 |
|
14 | 14 | ## subst
|
15 |
| -* `subst($text, $regex, $replacement, :$global?)` |
| 15 | +* `subst($text, $regex, $replacement, :$global? --> str)` |
16 | 16 |
|
17 |
| -Substitute a match of ```$regex``` in ```$text``` with ```$replacement```, |
18 |
| -returning the substituted string. If ```$global``` is given, then |
19 |
| -perform the replacement on all matches of ```$text```. |
| 17 | +Substitute a match of `$regex` in `$text` with `$replacement`, |
| 18 | +returning the substituted string. If `$global` is given, then |
| 19 | +perform the replacement on all matches of `$text`. |
| 20 | + |
| 21 | +# From `nqp/src/core/IO.nqp` |
| 22 | + |
| 23 | +## open |
| 24 | +* `open($filename, :$r, :$w, :$a, :$bin, :$enc, :$chomp --> $filehandle)` |
| 25 | + |
| 26 | +Open file `$filename`. Options: |
| 27 | ++ :w - open for writing |
| 28 | ++ :r - open for reading (default) |
| 29 | ++ :a - open for appending |
| 30 | ++ :bin - open in binary mode |
| 31 | ++ :enc - define encoding (default: `utf8`) |
| 32 | ++ :chomp - strip ending newlines (default: true) |
| 33 | + |
| 34 | +## close |
| 35 | +* `close($fh)` |
| 36 | + |
| 37 | +Close the file attached to file handle `$fh`. |
| 38 | + |
| 39 | +## slurp |
| 40 | +* `slurp ($filename --> str)` |
| 41 | + |
| 42 | +Returns the contents of `$filename` as a single string. |
| 43 | + |
| 44 | +## spew |
| 45 | +* `spew($filename, $contents)` |
| 46 | + |
| 47 | +Write the string value of `$contents` to `$filename`. |
| 48 | + |
| 49 | +## say |
| 50 | +* `say($string)` |
| 51 | + |
| 52 | +Write `$string` to `stdout` with a newline added. |
| 53 | + |
| 54 | +## note |
| 55 | +* `note($string)` |
| 56 | + |
| 57 | +Write `$string` to `stderr` with a newline added. |
| 58 | + |
| 59 | +## join |
| 60 | +* `join($delim, @array --> str)` |
| 61 | + |
| 62 | +Returns a string formed by joining each element of `@array` |
| 63 | +with the `$delim`. |
| 64 | + |
| 65 | +## print |
| 66 | +* `print($string)` |
| 67 | + |
| 68 | +Write `$string` to `stdout`. |
| 69 | + |
| 70 | +## stdin |
| 71 | +* `stdin(--> $filehandle)` |
| 72 | + |
| 73 | +Returns a file handle to `stdin`. |
| 74 | + |
| 75 | +## stdout |
| 76 | +* `stdout(--> $filehandle)` |
| 77 | + |
| 78 | +Returns a file handle to `stdout`. |
| 79 | + |
| 80 | +## stderr |
| 81 | +* `stderr(--> $filehandle)` |
| 82 | + |
| 83 | +Returns a file handle to `stderr`. |
| 84 | + |
| 85 | +# File handle (fh) methods |
| 86 | + |
| 87 | +Some methods available on the file handle (fh) returned from `open`. |
| 88 | +Other methods available of lesser interest not documented below are: |
| 89 | ++ flush |
| 90 | ++ get |
| 91 | ++ seek |
| 92 | ++ set-encoding |
| 93 | ++ set-nl-in |
| 94 | ++ t |
| 95 | ++ tell |
| 96 | ++ wrap |
| 97 | + |
| 98 | +## fh.slurp |
| 99 | +* `$fh.slurp()` |
| 100 | + |
| 101 | +Reads the entire file attached to file handle `$fh`. |
| 102 | + |
| 103 | +## fh.print |
| 104 | +* `$fh.print($string)` |
| 105 | + |
| 106 | +Write `$string` to the file attached to file handle `$fh`. |
| 107 | +An ending newline is not added. |
| 108 | + |
| 109 | +## fh.say |
| 110 | +* `$fh.say($string)` |
| 111 | + |
| 112 | +Write `$string` to the file attached to file handle `$fh`. |
| 113 | +An ending newline is added. |
| 114 | + |
| 115 | +## fh.close |
| 116 | +* `$fh.close()` |
| 117 | + |
| 118 | +Close the file attached to file handle `$fh`. |
| 119 | + |
| 120 | +## fh.readchars |
| 121 | +* `$fh.readchars($nchars)` |
| 122 | + |
| 123 | +Read `$nchars` characters from file handle `$fh`. |
| 124 | + |
| 125 | +## fh.eof |
| 126 | +* `$fh.eof` |
| 127 | + |
| 128 | +Returns true if end-of-file has been reached on file handle `$fh`. |
0 commit comments