I keep getting the error message: "Can't call method label on unblessed reference at ..."

The trouble is I'm almost positive that the reference IS indeed blessed. I double checked (and triple and etc.) all the relevant code, and when that didn't produce anything wrong, I used Data::Dumper and the Dumper method even reported that the reference was blessed! Here's the stuff, cut down, of course:

my $tableau; for my $p(0..6) { $tableau->[$p] = Pile->new({ max => 52 }); for (1..$p) { my $card = $deck->GetRandCard(); $card->state('down'); $tableau->[$p]->fill_pile($card); } my $card = $deck->GetRandCard(); $card->state('up'); $tableau->[$p]->fill_pile($card); } ... my $tab_imgs; my $i = 1; for(@$tableau) { ## Here's the line that's causing the problems -> my $c = ($_->cards())[0]->label(); my $photo = $canvas->Photo(-file => "$card_dir\\$c.$ext", -format => 'gif'); push @$tab_imgs, $canvas->createImage(50+$i++*50,500, -image => $pho +to); } # Stuff in pile.pm (tableau calls # new,fill_pile,get_rand_card) sub new { my $proto = shift; my $self = shift; my $class = ref($proto) || $proto; $self->{next} = 0; bless ($self, $class); return $self; } sub fill_pile { my $self = shift; my $cards = shift; $self->{cards} = [$cards,$self->{cards}]; } sub GetRandCard { my $pile = shift; my $card = ($pile->shuffle())->[0]; $pile->remove_card; return $card; } # oh, and before I forget, the data::dumper print up # this is of ($_->cards())[0], the thing that tries to call # label, but can't cause it's "not blessed" $VAR1 = [ bless( { 'state' => 'up', 'where' => bless( { 'next' => 0, 'max' => 52, 'cards' => [ bless( { 'state' = +> 'down', 'where' = +> $VAR1->[0]{'where'}, 'value' = +> '1', 'suit' => + 'h' }, 'Card' ) +, ##.. more stuff like this + ] }, 'Pile' ), 'value' => 'q', 'suit' => 's' }, 'Card' ), undef ];

I don't know if this will be enough, but I don't know what else may help short of giving a lot of code.

edited: Sat Jul 6 16:22:40 2002 by jeffa - title change (was: Help with error)


In reply to Help with unblessed object reference error 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.