Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here's a slightly modified version of your AlienFarm module... There are some subtle differences... Can you see what they are?
#!/usr/bin/perl -w package AlienFarm; use strict; sub birth { my $pkg = shift; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime +(time); my $name = shift; $mon++; $year+=1900; my $birth = "$mon $mday, $year"; my $alien = bless { NAME => "$name", BIRTH => "$birth", POWERS => [ ], BRAINS => ["pre-school", "1st grade", "2nd grade", "3rd grade", "4th grade", "5th grade", "6th grade", "7th grade", "8th grade", "9th grade", "10th grade", "11th grade", "12th grade", "Harvard Freshman", "Harvard Sophmo +re", "Havard Junior", "Harvard Senior", "Employed", "C +EO"], LEVEL => "-1" }, $pkg; } sub birthday { my $decide=shift; ref $decide ? $decide->{BIRTH} : "an unknown time"; } sub name { my $decide=shift; ref $decide ? $decide->{NAME} : "an unknown name"; } sub set_power { my $self=shift; my $power=shift; push @{$self->{POWERS}}, $power; } sub get_powers { my $self=shift; my $num=1; foreach my $power ( @{$self->{POWERS}} ) { print "$num => $power\n"; $num++; } print "\n"; } sub teach_lessons { my $self = shift; $self->{LEVEL}++; return "Lesson taught. Level: ". $self->{BRAINS}[$self->{LEVEL}] . +"\n"; } sub schooling { my $self = shift; return $self->{BRAINS}[$self->{LEVEL}]; }

Also, you can actually combine set_power and get_power into one sub, called power. But that's an exercise left for the reader...

Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com

In reply to Re: Re: Beginner's Object Orientation Exercises? by Necos
in thread Beginner's Object Orientation Exercises? by munchie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-24 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found