Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I made a Flashlight program.

#! Perl use vars qw($on $pwrlvl); use strict; my $on = "no"; my $pwrlvl = "3"; my $fl = "Flashlight"; print "You are holding a flashlight. What will you do? \n"; print "(TurnOn, TurnOff, Flash, ChangePowerLevel, ExitProgram)\n"; print "/Status Checks/=\\ pwrlvl, ison \\\n"; while(<STDIN>) { chomp; if (/^Change/) { print "Enter Level: "; chomp (my $lvl=<STDIN>); print $fl->ChangePowerLevel("$lvl"); print "\n"; } elsif (/^(exit|q|end|x|quit)/i) { exit; } else { print $fl->$_ ."\n"; } } { #1 package Flashlight; sub TurnOn { $on = "yes"; return "The light is on."; } sub TurnOff { $on = "no"; return "Light is now off."; } sub Flash { if ($on eq "no") { return "A flash of light beams through the air!"; } else { return "The flashlight is on already."; } } sub ChangePowerLevel { my $class = shift; my $level = shift; $pwrlvl = $level; return "The Power level is set at $pwrlvl"; } sub pwrlvl { return "Power is at $pwrlvl"; } sub ison { return "Is it on? Well, $on"; } }
It has everything but the battery power, which will be easy to implement in a few minutes when I find time.

Commands: ison, pwrlvl, ChangePowerLevel, TurnOn, TurnOff, Flash

> munchie, the number munchin newb
Llama: The other other white meat!
(you had to be there :-P)

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

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?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2023-03-27 00:06 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.