Re: Complex Objects in Perl

From: packat (chariya_at_verizon.not)
Date: 03/19/05


Date: Sat, 19 Mar 2005 16:55:09 GMT

Jim Gibson wrote:
> In article <8_ydnS49C86x9S3cRVn-tA@adelphia.com>, John
> Smith
> <someone@microsoft.com> wrote:
>
> Objects in Perl are implemented as a reference to an
> anonymous hash.
> The keys to the hash are the names of the members, and the
> values of
> the hash may be any scalar. This includes normal scalar
> values and
> references. Thus, a member of your object may be a
> reference to an
> array or a hash or it may be another object (reference to
> a hash) or a
> method (reference to subroutine). So you can have any
> level of nesting
> of objects-within-objects and arrays or hashes of other
> objects. You
> enumerate over array and hash members as you would
> enumerate over any
> array or hash given a reference to one of these.
>
> See the following documentation built into your
> installation of perl:
>
> 'perldoc perlreftut' Perl references tutorial
> 'perldoc perldsc' Perl data structures cookbook
> 'perldoc perllol' Manipulating arrays of arrays in
> Perl
> 'perldoc perlboot' Beginner's object-oriented
> tutorial
>

Thanks for the info. I have been using perl on and off but
never tried its OO feature.
I followed the example in perlcod perlboot but got an error.

Here is my code
--------------------

    Cow->speak;

{ package Animal;
  sub speak {
    my $class = shift;
    print "a $class goes ",$class->sound,"!\n";
  }
}

{ package Cow;
  use vars qw(@ISA);
  @ISA = qw(Animal);
  print "Hi >$ISA[0]>\n";
  sub sound {"Mooo"}
}
---------------------
After execution, I got

C:\Perl\MDGS>
C:\Perl\MDGS>
C:\Perl\MDGS>Sample.pl
Can't locate object method "speak" via package "Cow" at
C:\Perl\MDGS\Sample.pl line 2.

--------------------

Does this mean perl can't recgnize @ISA?

Thanks,
pac



Relevant Pages

  • Re: taking references to functions
    ... > I'm building a diagnostic medical questionnaire using Perl Tk. ... > to create a reference to a named function but not for unnamed ones. ... Notice that %dispatch here is an actual hash variable. ...
    (perl.beginners)
  • Making Datatypes Constant and Emulating Const Correctness
    ... Being relatively new to Perl with Java and bits of C under my belt, ... I'm new to C+++, too, but remember a number of uses for the const keyword ... an array to some analizer function as a constant strongly signals that no ... some reference (e,g. a blessed hash reference) ...
    (comp.lang.perl.misc)
  • My own handy Pocket Reference notes (please share your own also)
    ... hints/reminders from books and other usenet posts. ... Do you have some handy notes scratched inside YOUR Perl book? ... Here are my personal quick reference notes ... To pass a only single hash to a subroutine: ...
    (comp.lang.perl.misc)
  • RE: Array de-referencing problem
    ... But I guess it's better to use an array reference? ... Conversation: Array de-referencing problem ... The values of a hash can only be scalars! ...
    (perl.beginners)
  • Re: how do I print the name and value of a scalar
    ... Names like that are a very strong indication that an array would have ... Or often maybe instead of an index a more identifying name, i.e. a hash ... my @vars = qw; ... To jump the boundary between code and data in Perl you can use eval. ...
    (comp.lang.perl.misc)

Quantcast