And now for something completely different :)

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11162756 use warnings; Test(); sub hasSameChars { ( grep(defined, @_) or return 1 ) < @_ and return 0; my %same = map { do { my @count = (0) x 256; $count[ord $&]++ while /./gs; "@count" }, 1 } @_; return %same == 1 ? 1 : 0; } sub Test { my $ERRORS = 0; # TESTING TRUE: hasSameChars("Hello World!", "Hello World!") == 1 or + $ERRORS++; hasSameChars("Hello World!", "Hdll!ooreWl ") == 1 or + $ERRORS++; hasSameChars("Hello World!", "Hdll!ooreWl ", "Hlde! Wlloor") == 1 or + $ERRORS++; hasSameChars("FALLEN", "LENFAL", "ELFALN") == 1 or + $ERRORS++; hasSameChars(undef, undef, undef) == 1 or + $ERRORS++; hasSameChars('', '', '', '') == 1 or + $ERRORS++; hasSameChars('A', 'A', 'A', 'A') == 1 or + $ERRORS++; hasSameChars("\r\n\t\0\0\1", "\0\1\t\0\n\r", "\n\1\r\t\0\0") == 1 or + $ERRORS++; hasSameChars('ABB', 'BBA', 'BAB', 'BBA') == 1 or + $ERRORS++; hasSameChars(' ', ' ', ' ', ' ') == 1 or + $ERRORS++; hasSameChars("ABC", "CAB", "BAC", "BCA", "ACB", "ABC") == 1 or + $ERRORS++; # TESTING FALSE: hasSameChars("\r\n\t\0\1\2", "\0\2\t\1\n\r", "\t\t\r\1\2\n") == 0 or + $ERRORS++; hasSameChars("Hello World!", "Hdll!ooreWl ", "Hlde! Wlloo") == 0 or + $ERRORS++; hasSameChars("Hello World!", "Hdll!ooreWl") == 0 or + $ERRORS++; hasSameChars("ABC", "C_B", "BAC", "BCA", "ACB", "ABC") == 0 or + $ERRORS++; hasSameChars("ALLEN", "ELLEN", "HALLEN", "HELLEN") == 0 or + $ERRORS++; hasSameChars("FALLEN", "Lenfal", "ELFALN") == 0 or + $ERRORS++; hasSameChars("FALLEN", "FALLEN ") == 0 or + $ERRORS++; hasSameChars(undef, "FALLEN", "FALLEN") == 0 or + $ERRORS++; hasSameChars("FALLEN", undef, "FALLEN") == 0 or + $ERRORS++; hasSameChars("FALLEN", "FALLEN", undef) == 0 or + $ERRORS++; hasSameChars('', undef, undef) == 0 or + $ERRORS++; hasSameChars('ABB', 'ABA', 'BAA', 'BAA') == 0 or + $ERRORS++; hasSameChars(' ', ' ', ' ', "\t") == 0 or + $ERRORS++; print "ERRORS = $ERRORS\n"; }

Outputs:

ERRORS = 0

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.