我的 RAKU 代码:
sub comments {
if ($DEBUG) { say "<filtering comments>\n"; }
my @filteredtitles = ();
# This loops through each track
for @tracks -> $title {
##########################
# LAB 1 TASK 2 #
##########################
## Add regex substitutions to remove superflous comments and all that follows them
## Assign to $_ with smartmatcher (~~)
##########################
$_ = $title;
if ($_) ~~ s:g:mrx/ .*<?[\(^.*]> / {
# Repeat for the other symbols
########################## End Task 2
# Add the …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用数组中的哈希来查找数组中每个特定项目的键和值。当我没有对数组进行排序时,但当我创建一个排序数组时,我能够做到这一点,并且键和值都是分开的,例如:
my @sorted_pairs = %counts{$word}.sort(*.value);
Run Code Online (Sandbox Code Playgroud)
它将值绑定在一起。是否有一种排序哈希值的方法,允许将哈希值对拆分为数组中的单独实体?我希望能够分别访问“单词”字符串以及该单词被视为整数的计数或次数。
我使用这个来源作为参考。我已经尝试了其中一些方法,虽然它似乎确实按给定输出的数值对数组进行排序:
排序数组:[做=> 1休息=> 1看=> 1想要=> 1给予=> 1想象=> 2阅读=> 2授予=> 2曾经=> 2爱=> 2将=> 2感觉= > 2意味着=> 2喜欢=> 2你=> 2生活=> 3写=> 3来=> 3知道=> 3是=> 3妈妈=> 4]
它不会将键和值彼此分开。