我正在尝试对字符串列表/数组进行排序:
> my @e = Q (list_regex_files json_file_to_ref write_2d_array_to_tex_tabular dir get_sample_ID density_scatterplot violin_plot multiline_plot ref_to_json_file execute venn barplot scatterplot_2d_color worksheet_to_hash group_bar workbook_to_hash read_table)
Run Code Online (Sandbox Code Playgroud)
使用https://docs.raku.org/type/Array#(List)_routine_sort我尝试
> say @e.sort
(list_regex_files json_file_to_ref write_2d_array_to_tex_tabular dir get_sample_ID density_scatterplot violin_plot multiline_plot ref_to_json_file execute venn barplot scatterplot_2d_color worksheet_to_hash group_bar workbook_to_hash read_table)
Run Code Online (Sandbox Code Playgroud)
但
say <list_regex_files json_file_to_ref write_2d_array_to_tex_tabular dir get_sample_ID density_scatterplot violin_plot multiline_plot ref_to_json_file execute venn barplot scatterplot_2d_color worksheet_to_hash group_bar workbook_to_hash read_table>.sort
Run Code Online (Sandbox Code Playgroud)
确实有效。但是,如何将数据保存到数组中然后对其进行排序?喜欢say @e.sort
?
回应@Elizabeth 的评论,dd 是你的朋友......
> my @a1 = Q (a b c); dd @a1; #Array @a1 = ["a b c"]
> my @a2 = <a b c>; dd @a2; #Array @a2 = ["a", "b", "c"]
Run Code Online (Sandbox Code Playgroud)
这是任何过往读者的文档https://docs.raku.org/language/quoting
\n
Q
是引用域特定子语言的基础。
因此,它非常简单,它唯一做的就是原始引用。您甚至无法转义结束分隔符。
\nsay Q (a b c \\).raku\n# "a b c \\\\"\n
Run Code Online (Sandbox Code Playgroud)\n您可以为该基本语言启用额外功能,例如启用:backslash
. (:b
是别名)
say Q :backslash (a b c \\)).raku\n# "a b c )"\n
Run Code Online (Sandbox Code Playgroud)\n您可能认为:words
( :w
) 或:quotewords
( :ww
) 功能已启用。
say Q :words (a b c).raku\n# ("a", "b", "c")\n\nsay Q :quotewords (a b \'c d\' "e f").raku\n# ("a", "b", "c d", "e f")\n
Run Code Online (Sandbox Code Playgroud)\n其中一些功能非常有用,因此有其他方法可以编写它们。
\n例如,:single
( :q
) 功能允许在结束定界符中使用反斜杠,但通常仅用单引号拼写\'\xc2\xa0\'
。
\'a b c \\\' d\' eqv Q :single \'a b c \\\' d\' eqv Q:q \'a b c \\\' d\'\n
Run Code Online (Sandbox Code Playgroud)\nq
单引号还有另一个别名。
\'a b c \\\' d\' eqv q \'a b c \\\' d\'\n
Run Code Online (Sandbox Code Playgroud)\n还有一个捷径是拼写的<\xc2\xa0>
。
<a b c> eqv Q :single :words (a b c) eqv Q:s:w (a b c)\n
Run Code Online (Sandbox Code Playgroud)\n这是您认为自己正在使用的那个。
\n您可以启用或禁用更多功能。有关更全面的列表和示例,请参阅文档。
\n 归档时间: |
|
查看次数: |
48 次 |
最近记录: |