The full code of the bits I'm posting will be on my scratch pad (for those daring enough).

A brief synopsis:

I have three modules: right now I'm trying to get one of them to work with the other two. I've got a Pile type; a Card type; and a Solitaire type. Solitaire is working with Card and Pile. A pile is a collection of cards. I working with a sub to delete a card from a pile, and am running into some problems. Here's the sub:

sub remove_card { # usage: $caller->remove_card() # removes top card of pile, returning its value my $self = shift; if($self->num() > 1) { # I've worked with many alterations of this, and this # seems (I repeat *seems*) to be what I want $self->cards( $self->cards()->[1..$self->num()-1] ); } else { $self->cards([]) } }

The cards() method, which has undergone some tweaking as a result of my debugging attempts, looks like this:

sub cards { # usage: $caller->cards([$cards]) # $cards is an anonymous array of Card types # return: cards in pile my $self = shift; if (@_) { $self->{cards} = shift; $self->num(int @{$self->{cards}}); # From data dumping, it seems that I need this line for(@{$self->cards()}) { $_->where($self) } } return $self->{cards}; }

I think the problem lies with the splice in the remove procedure. I'm getting an error 'Argument "" isn't numeric...' for $self->num() statements (in the if and the splice in the remove procedure)

Also, 'Not an ARRAY reference' for $self->num(int @{$self->{cards}}); in cards() method.

In remove_card(), here's a data dump -----------------------------------------------

$self->cards() returns $VAR1 = [ bless( { 'state' => 'down', 'where' => bless( { 'next' => 0, 'num' => 56, 'max' => 52, 'cards' => $VAR1 }, 'Pile' ), 'value' => 1, 'suit' => 'h' }, 'Card' ), ... bless( { 'state' => 'down', 'where' => $VAR1->[0]{'where'}, 'value' => 'k', 'suit' => 'd' }, 'Card' ) ]; @{$self->cards()}->[1..$self->num()-1] returns $VAR1 = bless( { 'state' => 'down', 'where' => bless( { 'next' => 0, 'num' => 56, 'max' => 52, 'cards' => [ $VAR1, bless( { 'state' => +'down', 'where' => +$VAR1->{'where'}, 'value' => +8, 'suit' => ' +c' }, 'Card' ), ... bless( { 'state' => +'down', 'where' => +$VAR1->{'where'}, 'value' => +'k', 'suit' => ' +d' }, 'Card' ) ] }, 'Pile' ), 'value' => 1, 'suit' => 'h' }, 'Card' );

It looks like the key 'where' is getting the correct pile, but the actual pile is NOT getting changed as needed.


In reply to Perl OO and dereferincing help by dimmesdale

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.