Your getStringIDs()
method returns an array reference.
The regex binding operator (=~
) expects a string on its left-hand side. So it converts your array reference to a string. And a stringified array reference will look something like ARRAY(0x1ff4a68)
. It doesn't give you any of the contents of the array.
You can get from your array reference ($strings
) to an array by dereferencing it (@$strings
). And you can stringify an array by putting it in double quotes ("@$strings"
).
So you could do something like this:
ok("@$strings" =~ /BACK/);
But I suspect, you want word boundary markers in there:
ok("@$strings" =~ /\bBACK\b/);
And you might also prefer the like()
testing function.
like("@$strings", qr[\bBACK\b], 'Strings array contains BACK');
Update: Another alternative is to use grep
to check that one of your array elements is the string "BACK".
# Note: grep in scalar context returns the number of elements
# for which the block evaluated as 'true'. If we don't care how
# many elements are "BACK", we can just check that return value
# for truth with ok(). If we care that it's exactly 1, we should
# use is(..., 1) instead.
ok(grep { $_ eq 'BACK' } @$strings, 'Strings array contains BACK');
Update 2: Hmm... the fact that you're using constants here complicates this. Constants are subroutines and regexes are strings and subroutines aren't interpolated in strings.