in reply to Re: Check if string A and B are made up of same chars
in thread Check if string A and B are made up of same chars

Well, let's see:

X:\>perl 11162789.pl Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "1/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. ERRORS = 0 X:\>perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x +64-multi-t hread Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. X:\>

Line 16 is this one:

return %same == 1 ? 1 : 0;

Prior to Perl 5.25, a non-empty hash in scalar context returned a STRING containing used and allocated buckets, separated by a slash. After that, a hash in scalar context returns the number of keys in the hash. Obviously, you did not consider that. keys %same would always return the number of keys.

And while we are at it, let's see what happens once you leave the 8 bit world and process Unicode strings. Adding the following line to the "TESTING FALSE" lines:

hasSameChars("ABC\x{ABCD}", "ABC\x{CDEF}") == 0 or + $ERRORS++;
... Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Terminating on signal SIGBREAK(21) Use of uninitialized value in join or string at 11162789.pl line 14. Terminating on signal SIGBREAK(21) Use of uninitialized value in join or string at 11162789.pl line 14. X:\>

Yes, it seems that it does not terminate. Actually, it would terminate, after issuing many, many warnings. Much more than I'm willing watch scrolling across my screen.

Line 14 is this line:

"@count"

Let's change my change to use "ABC\x{101}" and "ABC\x{102}" to see what happens:

... Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Use of uninitialized value in join or string at 11162789.pl line 14. Argument "2/8" isn't numeric in numeric eq (==) at 11162789.pl line 16 +. ERRORS = 0 X:\>

Well, it seems you don't know Unicode at all, or you just completely ignored it.

Both is sad.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^3: Check if string A and B are made up of same chars
by LanX (Saint) on Nov 18, 2024 at 19:24 UTC
    Funny enough, always ERRORS = 0

    So either he just needs to silence the warnings or the OP has to work on his test suite...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery