Good Day, I'm working on a Module for working with permutation groups. I always use strict, warnings, and I even write (and run) test scripts while I write the module! I am completely confused by this problem though. I have the following test script:
use strict; use warnings; use Group::Permutation; my $x = new Group::Permutation qw(1 3 2 4); print "x = $x\n"; print 'x of 2 = ',$x->of(2),"\n"; print 'ref of x of 2: ', ref $x->of(2),"\n"; print "x of 2 is three!\n" if ($x->of(2) == 3);
This produces the output:
x = (1, 3, 2, 4) x of 2 = 3 ref of x of 2:
Most notably, the test ($x->of(2) == 3) fails. I can't figure out why this happens.

The ref test was put in because I overloaded == and I wanted to make sure perl wasn't calling the wrong == (I also added a print statement to the == code).

For complete disclosure of information:
sub of { my $x = shift; my @y = map { $_-1 if defined && /^\d+$/ && $_>0 } @_; # protect the caller from placement errors return undef unless ($#y == $#_); return map { ($_<$$x{'n'}) ? $$x{'perm'}[$_] + 1 : $_+1 } @y; }
and
sub new { # SNIP # BEGIN vicious error checking # all input must be legitimate $x{'perm'}=[ map { $_-1 if defined and /^\d+$/ and $_ > 0} @_ ]; return undef unless $#{$x{'perm'}} == $#_; # it must really be a permutation of 0..n-1 return undef unless join(' ',sort { $a <=> $b } @{$x{'perm'}}) eq +join(' ',0..$#{$x{'perm'}}); # END error checking # SNIP $x{'n'} = scalar @{$x{'perm'}}; # for clarity in other places bless \%x, $class; }
The snipped sections are just some definitions and option parsing.

Thanks,

    -Dean


In reply to (x == 3 && x != 3) by duelafn

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.