Thanks guys!

 I've been reading everything I can about Perl and although I've read
Learning Perl, and have been referencing Programming Perl, The Perl
CookBook, Modern Perl Programming and using the Perl Debugger mini
book, I must say, there's alot about Perl I don't yet understand. All
I know so far is it's amazingly powerfull and up until I started
trying to create a structure, I thought it was pretty straightforward.

A couple things:
1. What's "od HoA" ??
2. I know you don't remove use strict to eliminate errors!! (jeez)
3. What is the alternative to Class::Structs if I want to create some
"data aggregates"? od Hoa?

One book I have (Modern Perl Programming, Saltzman 2002) has some good
stuff in Chapter 11 (Object Oriented Programming) I'm investigating.

Anyway, thanks for the help. I'll post again when I get my mind around
a solution or if I have some more questions!

Thanks again,
Ed



On 4/10/06, Jay Savage <[EMAIL PROTECTED]> wrote:
>  On 4/10/06, Ed <[EMAIL PROTECTED]> wrote:
> > Thanks for the reply.
> >
> > Yes, I see I fat fingered the owner/some_owner variable.
> >
> > It does compile on my system (if I omit use strict). I should add that
> > I'm running Perl 5.6.1 because some of the code I'm maintaining needs
> > this version.
> >
> > Except for the last 7 lines where I'm trying to print out the field
> > elements, I pulled all the code from here:
> > http://www.unix.org.ua/orelly/perl/prog3/ch32_06.htm
> >
> > Again, this compiles on my system if I omit use strict. If I add use
> > strict it instructs me that I need to
> > Global symbol "$store" requires explicit package name at
> > classexample.pl line 18.
> > Global symbol "$store" requires explicit package name at
> > classexample.pl line 19.
> > ...
> >
> > If I specify
> > $Shoppe::store = Shoppe->new();
> > and
> > $Shoppe::store->owner('Abdul Alhazred');
> > etc,
> > It passes the use strict specification, but it still fails at
> > print "owner: $Shoppe::store->owner()\n";
> > $some_owner =  $Shoppe::store->owner();
> > print "owner: $some_owner\n";
> >
> > If I omit use strict it prints out the
> > Do I need to put the Class definition in a separate file and call it a
> > package, and then instruct my script to "use Shoppe"? That doesn't
> > seem right.
> >
> > I'm pretty stumped, so thanks for your help. I think I'm pretty close.
> >
> > Ed
>
> My advice? stay away frmo Class::Struct if you can. What does it give
> you that a plain od HoA won't? That said, for motives that have never
> been clear to me--i guess just a blind desire to imititate C for
> reasons unknown--declaring an element to be of a strct type doesn't
> save you from having to initialize it. Better still, you can't even
> initialize it in the declaration, you have to call new later. you can
> do that either when you call new on the parent struct, or any time
> before you want to use it. I've given both examples below.
>
> Also, the solution to getting errors under use strict is to fix the
> errors, not turn off use strict. If you don't understand lexical
> scoping, pick up any basic Perl book, or ask here.
>
> The code below is tested:
>
>    #!/usr/bin/perl -w
>    use strict;
>
>    use Class::Struct;
>
>    struct ( Manager => {         # Creates a Manager->new() constructor.
>        name    => '$',         # Now name() method accesses a scalar value.
>        salary  => '$',         # And so does salary().
>        started => '$',         # And so does started().
>    });
>
>    struct ( Shoppe => {          # Creates a Shoppe->new() constructor.
>        owner   => '$',         # Now owner() method accesses a scalar.
>        addrs   => '@',         # And addrs() method accesses an array.
>        stock   => '%',         # And stock() method accesses a hash.
>        boss    => 'Manager',   # Initializes with Manager->new().
>    });
>
>    my $store = Shoppe->new();
>        # or my $store = Shoppe->new('boss'=>Manager->new());
>    $store->owner('Abdul Alhazred');
>    $store->addrs(0, 'Miskatonic University');
>    $store->addrs(1, 'Innsmouth, Mass.');
>    $store->stock("books", 208);
>    $store->stock("charms", 3);
>    $store->stock("potions", "none");
>        # skip next line if 'boss' initialized above
>    $store->boss(Manager->new());
>    $store->boss->name('Prof L. P. Haitch');
>    $store->boss->salary('madness');
>    $store->boss->started(scalar localtime);
>
>    print "owner: $store->owner";
>    # prints ref
>    # you want print "owner: ", $store->owner";
>    my $owner =  $store->owner;
>    print "owner: $owner";
>
>    print "addrs: $store->addrs";
>    # see above
>    my @some_addrs  = $store->addrs;
>    print "addrs: @some_addrs";
>
>
> HTH,
>
> -- jay
> --------------------------------------------------
> This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
> private and confidential
>
> daggerquill [at] gmail [dot] com
> http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org
>
> values of β will give rise to dom!
>


--
Ed

Reply via email to