"Anagram" test seems to be broken

“Anagram” test seems to be broken

Can you share in what way it seems broken? Is it broken for just you or do you think all the solutions are not working?

What was your input? What is the error? (Please use codeblocks to share code and errors.)

I’ve checked the exercise and unfortunately I can’t see which problem you’re referring to as I’m able to solve it without issue. Could you submit the implementation you have for code review?

1 Like


Test 11

anagrams must use all letters exactly once


    match_anagrams( "go", ["go Go GO"] ),
    bag {
    "does not detect an anagram if the original word is repeated",


# Failed test 'anagrams must use all letters exactly once'
# at /mnt/exercism-iteration/anagram.t line 113.
# +------+-----------------------+---------+------------------+----------+
# | PATH | GOT                   | OP      | CHECK            | LNs      |
# +------+-----------------------+---------+------------------+----------+
# |      | ARRAY(0x55e4f07123a0) |         | <BAG>            | 111, 111 |
# | [0]  | patter                | !exists | <DOES NOT EXIST> |          |
# +------+-----------------------+---------+------------------+----------+


1. tapper patter 
p tapper a tapper t tapper t tapper e tapper r tapper 4.patter
package Anagram;

use v5.38;

use Exporter qw<import>;
our @EXPORT_OK = qw<match_anagrams>;

sub match_anagrams ( $subject, $candidates ) {
    my @out = ();
    for my $item (@$candidates) {
        print "1. $subject ", $item, "\n";
        next if length($item) != length($subject);
        #print "2.", $item, "\n";
        next if uc $item eq uc $subject;
        #print "3.", $item, "\n";
        my $matched = 1;
        for my $i (split //, $item) {
            print "$i $subject ";
            if ($subject !~ m/$i/i) {
                print "not matched\n";
                $matched = 0;
        print "4.", $item, "\n" if $matched;
        push @out, $item if $matched;
    return \@out;
1 Like

I am just awestruck to see the words “tapper” and “patter” when the input is all “Go”

Also, may I request you to share any link on documentation on the “bag” type in Perl?

Ah, I see the problem. Your print statement on line 18 does not have a newline, which is interfering with the TAP output from the test file and causing the test runner to misread the output from the test.

I will look into what I can do to address this. In the meantime I would advise following the guidelines in the ‘How to debug’ section:

How to debug

When a test fails, a message is displayed describing what went wrong. If you would like additional output, you can use the subroutine ::YYY() around the code you would like to inspect. (:: is a shortcut for main::). This subroutine is part of the XXX module.

You may also simply print a message using the say function, e.g., say 'Hello, World!';.

1 Like

There is some documentation on the tests here: Testing on the Perl track | Exercism's Docs

The bag subroutine is part of the Test2::V0 test suite. Documentation for it can be found here: Test2::Tools::Compare - Tools for comparing deep data structures. - metacpan.org

A bag is like an array, but we don’t care about the order of the items. In the example, $check would match both ['a','b'] and ['b','a'].

1 Like