Raku 中的动态变量
— 焉知非鱼Dynamic Variables in Raku
Raku 中的动态变量
$*ARGFILES #
$*ARGFILES Magic command-line input handle.
argfiles.raku
$*ARGFILES.raku.say; # IO::Handle.new(:path(Any),:chomp)
# 按行读取
for $*ARGFILES.lines -> $line {
say "$line";
}
# 一次性读取
# say $*ARGFILES.slurp;
USAGE
$ raku argfiles.raku file1 file2 file3 ...
@*ARGS #
@*ARGS - Arguments from the command line. 命令行中的参数。
agrs.raku
say @*ARGS.WAHT; # (Array)
say @*ARGS; # [a b c d e]
say @*ARGS.raku; # ["a", "b", "c", "d", "e"]
USAGE
$ raku args.raku a b c d e
$*IN #
$*IN - 标准输入文件句柄, 等同于 stdin
in.raku
say $*IN.raku; # IO::Handle.new(:path(IO::Special.new(what "<STDIN>")),:chomp)
say $*IN.path; # IO::Special.new(what "<STDIN>")
say $*IN.chomp; # True
for $*IN.lines -> $line {
say "$line";
}
USAGE
$ raku in.raku
人力
...
$ cat somefile.txt | raku in.raku
$*OUT #
$*OUT - 标准输出文件句柄, 等同于 stdout
out.raku
say $*OUT.raku; # IO::Handle.new(:path(IO::Special.new(what "<STDOUT>")),:chomp)
say $*OUT.path; # IO::Special.new(what "<STDOUT>")
say $*OUT.chomp; # True
$*OUT.say( q:to/新年快乐/ );
祝你新年快乐
2016.01.23
让我再说一次
新年快乐
# 通常我们会在打印时省略 $*OUT
# say "哈利路亚";
最后一段代码中 //
中间的字符是分割符。这打印出:
祝你新年快乐
2016.01.23
让我再说一次
USAGE
$ raku out.raku
$ raku out.raku > result.txt
$*ERR #
$*ERR - 标准错误文件句柄, 等同于 stderr
err.raku
say $*ERR.raku; # IO::Handle.new(:path(IO::Special.new(what "<STDERR>")),:chomp)
say $*ERR.path; # IO::Special.new(what "<STDERR>")
say $*ERR.chomp; # True
$*ERR.say("我错了");
# 平时可以使用 note
# note "前方高能预警";
USAGE
$ raku err.raku > /dev/null
我错了
$*REPO #
$*REPO A variable holding information about modules installed/loaded
repo.raku
say $*REPO;
say $*REPO.raku;
say $*REPO.id;
say $*REPO.path-spec;
say $*REPO.loaded;
say $*REPO.repo-chain;
$*TZ #
$*TZ The system’s local timezone.
tz.raku
say $*TZ; # 32400
say $*TZ.raku; # 32400
say $*TZ.WHAT; # (Int)
$*CWD #
$*CWD The Current Working Directory.
cwd.raku
say $*CWD; # "/Users/kujira".IO
say $*CWD.path; # /Users/kujira
say $*CWD.raku; # "/Users/kujira".IO(:SPEC(IO::Spec::Unix),:CWD("/Users/kujira"))
$*KERNEL #
$*KERNEL Which kernel am I compiled for?
kernel.raku
say $*KERNEL; # darwin (15.2.0)
say $*KERNEL.release; # Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64
say $*KERNEL.name; # darwin
say $*KERNEL.auth; # unknown
say $*KERNEL.version; # v15.2.0
say $*KERNEL.signature; # (Blob)
say $*KERNEL.desc; # (Str)
say $*KERNEL.raku; # Kernel.new(release Str, name "darwin", auth "unknown", version Version.new('15.2.0'), signature Blob, desc Str)
say $*KERNEL.WHAT; # (Kernel)
$*DISTRO #
$*DISTRO Which OS distribution am I compiling under?
distro.raku
say $*DISTRO; # macosx (10.11.2)
say $*DISTRO.name; # macosx
say $*DISTRO.is-win; # False
say $*DISTRO.version; # v11.4
say $*DISTRO.path-sep; # :
say $*DISTRO.auth; # Apple Computer, Inc.
say $*DISTRO.desc; # unknown
say $*DISTRO.release; # 20F71
say $*DISTRO.signature; # (Blob)
say $*DISTRO.gist; # macosx (11.4)
say $*DISTRO.Str; # macosx
say $*DISTRO.raku; # Distro.new(release "20F71", path-sep ":", name "macos", auth "Apple Inc.", version v11.4, signature Blob, desc "unknown")
$*VM #
$*VM Which virtual machine am I compiling under?
vm.raku
say $*VM; # moar (2021.06)
say $*VM.config;
say $*VM.raku;
$*RAKU #
$*RAKU Which Raku am I compiled for?
perl.raku
say $*RAKU; # Raku (6.d)
say $*RAKU.compiler; # rakudo (2021.06)
say $*RAKU.raku; # Raku.new(compiler Compiler.new(id "24F69C23F0D9F44910DEB9B097353B0DD30C7E96", release "", codename "", name "rakudo", auth "The Perl Foundation", version v2021.06, signature Blob, desc Str), name "Raku", auth "The Perl Foundation", version v6.d, signature Blob, desc Str)
$*PID #
$*PID Process ID of the current process.
pid.raku
say $*PID; # 35480
say $*PID.raku; # 35480
say $*PID.WHAT; # (Int)
$*PROGRAM-NAME #
$*PROGRAM-NAME Path to the current executable as it was entered on the command line, or C<-e> if perl was invoked with the -e flag.
program-name.raku
say $*PROGRAM-NAME;
say $*PROGRAM-NAME.raku;
say $*PROGRAM-NAME.IO.basename;
$*PROGRAM #
$*PROGRAM Location (in the form of an CIO::Path object) of the Perl program being executed.
program.raku
say $*PROGRAM; # "/Users/kujira/program.raku".IO
say $*PROGRAM.Str; # program.raku
say $*PROGRAM.raku; # "program.raku".IO(:SPEC(IO::Spec::Unix),:CWD("/Users/kujira"))
say $*PROGRAM.SPEC; # (Unix)
say $*PROGRAM.CWD; # /Users/kujira
say $*PROGRAM.WHAT; # (Path)
$*EXECUTABLE #
$*EXECUTABLE Absolute path of the perl executable that is currently running.
executable.raku
say $*EXECUTABLE; # "/usr/local/bin/raku".IO
say $*EXECUTABLE.Str; # /usr/local/bin/raku
say $*EXECUTABLE.basename; # raku
say $*EXECUTABLE.WHAT; # (Path)
say $*EXECUTABLE.raku; # "/usr/local/bin/raku".IO(:SPEC(IO::Spec::Unix))
say $*EXECUTABLE.SPEC; # (Unix)
$*EXECUTABLE-NAME #
$*EXECUTABLE-NAME The name of the perl executable that is currently running. (e.g. raku-p, raku-m, Niecza.exe) Favor $*EXECUTABLE because it is not guaranteed that the perl executable is in PATH.
executable-name.raku
say $*EXECUTABLE-NAME; # raku
say $*EXECUTABLE-NAME.WHAT; # (Str)
$*USER #
$*USER The user that is running the program. It is an object that evaluates to “username (uid)”. It will evaluate to the username only if treated as a string and the numeric user id if treated as a number.
user.raku
say $*USER; # kujira (801)
say +$*USER; # 801
say ~$*USER; # kujira
say $*USER.raku; # IdName.new
$*GROUP #
$*GROUP The primary group of the user who is running the program. It is an object that evaluates to “groupname (gid)”. It will evaluate to the groupname only if treated as a string and the numeric group id if treated as a number.
group.raku
say $*GROUP; # whale (0)
say ~$*GROUP; # whale
say +$*GROUP; # 0
say $*GROUP.raku; # IdName.new
$*HOME #
$*HOME An LIO::Path object representing the “home directory” of the user that is running the program. If the “home directory” cannot be determined it will be L
home.raku
say $*HOME; # "/Users/kujira".IO
say $*HOME.CWD; # /Users/kujira
say $*HOME.SPEC; # (Unix)
say $*HOME.WHAT; # (Path)
say $*HOME.raku; # "/Users/kujira".IO(:SPEC(IO::Spec::Unix),:CWD("/Users/kujira"))
$*SPEC #
$*SPEC The appropriate IO::Spec sub-class for the platform that the program is running on.
spec.raku
say $*SPEC; # (Unix)
say $*SPEC.raku; # IO::Spec::Unix
say $*SPEC.path; # (/usr/local/Cellar/rakudo-star/2015.12/share/raku/site/bin /usr/local/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin)
say $*SPEC.tmpdir; # "/var/folders/9v/wr31l2zj78x1nw58jgljq_9w0000gn/T".IO
say $*SPEC.dir-sep; # /
say $*SPEC.curdir; # .
say $*SPEC.updir; # ..
say $*SPEC.curupdir; # none(., ..)
say $*SPEC.rootdir; # /
say $*SPEC.devnull; # /dev/null
- class IO::Spec - Raku Documentation
- class IO::Spec::QNX - Raku Documentation
- class IO::Spec::Unix - Raku Documentation
- class IO::Spec::Win32 - Raku Documentation
- class IO::Spec::Cygwin - Raku Documentation
http://qiita.com/B73W56H84/items/18053bf37de8bb2bb808#%E5%8F%82%E8%80%83%E3%81%A8%E6%B3%A8%E9%87%88