Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my %hash;
- sub count_each_chars($val) {
- if %hash<$val>:exists {
- %hash<$val> = %hash<$val> + 1
- } else {
- %hash<$val> = 1
- }
- }
- "rakuprogramming".comb.map(&count_each_chars);
- say %hash
- # I was expecting {a => 2, g => 2, i => 1, k => 1, m => 2, n => 1, o => 1, p => 1, r => 3, u => 1}
- # But I get {$val => 15}
- # I know the other way to solve this problem but I want to try this method
- # What am I missing?
Add Comment
Please, Sign In to add comment