Hmm.. your package C isn't fit for use:
package C; use strict; use base qw(model type); 1; __END__ $ perl -e 'use C' Base class package "model" is empty. (Perhaps you need to 'use' the module which defines that package f +irst.) at C.pm line 5 BEGIN failed--compilation aborted at C.pm line 5.

Working code to scrutinize would help to help.

Apart from that, you might want to have a look at Spiffy.

package A; use Spiffy -Base; use strict; field $_ for qw(id name); sub new { bless {}, $self }
package B; use A -Base; use strict; field $_ for qw(addr phone city); sub new { bless {}, $self }
package C; use A -Base; use strict; field $_ for qw(model type); sub new { bless {}, $self }
#!/usr/bin/perl use strict; use B; use C; use Data::Dumper; $Data::Dumper::Indent = 1; my $foo = new C; $foo->id(123); $foo->name("thingy"); $foo->model("Z80"); my $bar = new B; $bar->id(456); $bar->city("Lhasa"); $bar->name("kouxuan"); print Dumper($foo); print Dumper($bar); __END__ $VAR1 = bless( { 'model' => 'Z80', 'name' => 'thingy', 'id' => 123 }, 'C' ); $VAR1 = bless( { 'city' => 'Lhasa', 'name' => 'kouxuan', 'id' => 456 }, 'B' );

Spiffy rocks ;-)

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Cross reference between two classes and FIELDS by shmem
in thread Cross reference between two classes and FIELDS by nite_man

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.