Hi all.

In my never-ending quest for perl knowledge, I am teaching myself how to work with objects, classes, packages, etc. The following code is my first such script. I would be most appreciative if you could make some helpful comments / criticisms / etc. regarding how I might improve this fragile foundation.
Thanks,
-Katie.
#!/usr/bin/perl -w #class file. package Food; use strict; sub new { my $meal = { beverage => "Pepsi", entree => "soup", dessert => "ice cream", }; bless( $meal ); return $meal; } sub dessert { my $self = shift(); $self->{ dessert } = shift() if ( @_ ); return $self->{ dessert }; } sub entree { my $self = shift(); $self->{ entree } = shift() if ( @_ ); return $self->{ entree }; } sub beverage { my $self = shift(); $self->{ beverage } = shift() if ( @_ ); return $self->{ beverage }; } sub setMeal { if ( @_ == 4 ) { my $self = shift(); $self->dessert( $_[ 0 ] ); $self->entree( $_[ 1 ] ); $self->beverage( $_[ 2 ] ); } else { print( "Method setMeal requires additional args.\n" ); } } sub display { my $self = shift(); print( $self->dessert ); print( ", " ); print( $self->entree ); print( ", and " ); print( $self->beverage ); } 1;

#!/usr/bin/perl -w use Food; use strict; my $meal = new Food; $meal->setMeal( "iced tea", "salad", "cheesecake" ); print "I would like "; $meal->display(); print " please."; print( "\n" );


In addition, if you know of a good OOP book for perl ( aside from the excellent Conway text ), could you post it? My former college professor ( Jerry ), a few other students and I are going to start work on a major perl project this Fall. He hasn't provided us with any other details but I'm already looking forward to it.

Edit kudra, 2002-08-05 Added a READMORE tag


In reply to Object Oriented Programming in Perl. by DigitalKitty

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.