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

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.