Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It's simple. ok($$) is a subroutien exported by one of the Test modules. It takes two arguements and compares them for equality. If they're equal, the test passes, if not, the test doesn't pass.

As to the specifics of his code, theres really two main parts. The inner most part is the keys map { $_->product_name() => } @classes }. This does two things. First the map statement is evaluated and loops through the @classes array, and produces a new list, consisting of every element in @classes interspersed with 1s. So the new list looks like (foo,1,bar,1,baz,1), where foo, bar, and baz are class names in @classes. Then the keys function treats the list that map returns as a hash, and creates a list consisting of all the keys in the new hash. Note that there is some implicit magic going on here, in that a hash can not have two keys with the same name, so if two such keys exists, the first one is ignored and only the last one is returned. This has the effect of returning only a unique list of values.

Then the list is simply turned in to a number by the scalar operator and compared to the scalar value of @classes. If they are different, then @classes contains multiple items with the same name.

In bash/linux terms, you might think of it like this: (Warning, pseudo code)
$lc1 = wc -l my_file.txt; $lc2 = sort my_file.txt | uniq | wc -l; if( $lc1 != $lc2 ) { #test fails } else { #test good! }

I played around with the example code and, in the presented form, I can't get it to even compile:
>perl -e"@x=qw/foo bar/; print scalar keys map { $_ => 1 } @x;"
Type of arg 1 to keys must be hash (not map iterator) at -e line 1, ne +ar "@x;" Execution of -e aborted due to compilation errors.

This is a trivial "bug" to fix, you simply enclose the map in %{{}} (Which first creates an anonymous hash reference out of a list, then derefences it back in to a hash, which keys will work upon), but in the presented form it doesn't appear to work. This is perl, v5.8.3 built for MSWin32-x86-multi-thread.

In reply to Re: Re: Tripwire tests and future-proofing by BUU
in thread Tripwire tests and future-proofing by dws

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (3)
    As of 2018-06-25 06:25 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.