Though I'm making progress (thanks guys) I'm still having a problem
with dereferencing the struct elements. I've re-read the section on
References in Programming Perl and I thought what I was doing was
correct, but I can't print out the values correctly. Here's a
simplified version of what I'm trying to to:


   use strict;
   use warnings;
   use Class::Struct;

   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.
   });

   my $store = Shoppe->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");


   # prints the reference.
   print "addrs: $store->addrs";
   # dereference the array and print it out
   print "addrs: @{$store->addrs}";

   # dreference the the addr array ref and assign it to annother array
and print it out.
   my @some_addrs  = @{$store->addrs};
   print "addrs: @some_addrs";

   # Print the hash reference:
   print "stock: $store->stock";

   # dereference the hash method.
   print "stock: %{$store->stock}";   ### <---FAILS! Prints out the
ref again with a % in front...

   # What about the scaler reference?
   # prints the reference.
   print "owner: $store->owner";

   # prints ref
   # you want print "owner: ", $store->owner";
   my $owner =  $store->owner;       ## This works.
   print "owner: $owner";

   # but how do you print the store owner directly? The following fails!
    print "owner:, ${$store->owner}";

Thanks in advance,

Ed

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to