Update : Fixed a number of bugs by help of bart.

Update : By blazar's advice, removed the exit 0; at the end. CB questioning revealed it to be unneccessary(sp?). Well, learned something new... guess it's my Pascal habit of ending my scripts.

Update : I think g0n, having quite some experience in building (be it evil) robots, would perhaps be best-suited for building the Linux-running dishwashbot.
According to g0n, this, ummm... wouldn't work. Yes. Any volunteers? ;-)

As seen in Level 26: Saint, there is a growing problem
in the Monastery since no one dares to clean the dishes
because of Mr. Bones.

I wrote a little script to automate it. Now if a tech-monk
could perhaps build the robot to do it?

This is not meant to run, there might be mistakes in it, I'm only a novice to Perl. Have fun.

-- Detonite
#!/usr/bin/perl use strict; use warnings; use kitchen qw(kitchenSink); #imports kitchen stuff we need my $sink = new kitchenSink; my @dirties = kitchenSink->get('DIRTIES'); #get all dirty dishes and o +ther utensils if(@dirties) { #there're dirty dishes! my @tub = new $sink->tub; #cleaning tub my @clean = new $sink->dryrack; push(@tub, $sink->liquid_soap); push(@tub, $sink->faucet(water('HOT'))); push(@tub, $sink->brush); while(@dirties) { push(@tub, shift @dirties ); while(dirty($tub[-1])) { clean($tub[-1]) } push(@clean, pop @tub ); #add to dry rack } while(@clean) { put_away($_, getLocation($_)); #returns cleaned item, involves $dr +yingCloth } } print "We're done!\n";

Replies are listed 'Best First'.
Re: Cleaning the Monastery dishes
by planetscape (Chancellor) on Oct 03, 2005 at 08:39 UTC

    I want to be the very first to thank our enterprising young Wizardling for this, as I for one am getting tired of picking the little crusties off my plates.

    planetscape
Re: Cleaning the Monastery dishes
by gargle (Chaplain) on Oct 03, 2005 at 09:34 UTC

    Hi,

    Interesting! But I have a little question.

    Is sink using something like a tub and/or dryrack pool? To me it seems there is a new tub and a new dryrack used for each dirty dish. It looks like the number of tubs and pools are unlimited.

    I haven't seen the monastry kitchen, the NodeReaper scares me away each time. It can't be that the kitchen is so big, is it?

    --
    if ( 1 ) { $postman->ring() for (1..2); }
      Smart thinking... and taking my script a tad too seriously ;-)
      The reason I wrote it like this is because I basically translated the way I do the dishes into Perl code.
      So I go to the kitchen sink, grab a tub, grab a drying rack, etc etc.
      I could have made the tub and rack methods of kitchenSink... but I think it's fine the way it is.
      Thanks for pointing it out to me, though :)

      -- Detonite, resident PM Wizardling
Re: Cleaning the Monastery dishes
by atcroft (Abbot) on Oct 03, 2005 at 19:04 UTC

    Good show! Might I suggest importing a dishwasher object from the kitchen module, though, in which case the process might be a little shorter....

    #!/usr/bin/perl use strict; use warnings; use kitchen qw(kitchenSink dishwasher); my $sink = new kitchenSink; my @dirties = kitchenSink->get('DIRTIES'); my $washer = new dishwasher( 'dry_method' => 'heat', 'wash_cycle' => 'high' ); while (@dirties) { $washer->load(shift @dirties) while (not $washer->is_full); $washer->add('detergent'); $washer->add('rinse_agent') if ($washer->has_a('rinse_agent_dispenser')); $washer->close('door'); $washer->run; my @clean = $washer->unload; while (@clean) { put_away($_, getLocation($_)); } } print "We're done!\n";

    This does assume, however, that the version of the kitchen module used has support for a dishwasher object, though.

    If you want to be really "on the ball", you might want to look at using multiple processes or threads, so the next washing/unload actions could be in progress while you are putting away the previous load's clean dishes.

Re: Cleaning the Monastery dishes
by jdporter (Paladin) on Oct 03, 2005 at 19:19 UTC
    Pfaugh.
    mess: $dishesFactory = DishesFactory->instance; # singleton Sendmail->send( $dishesFactory, "I need clean dishes" ); @dishes = $dishesFactory->get; use @dishes; DESTROY @dishes; sleep until next $mealtime; goto mess;

      We tell the children and we tell the children: use strict; use warnings;.

      Just adding a comment does not a singleton make, and if it is a singleton why do you need an assignment inside the loop?

      Is there not a send member on the DishesFactory object? If you use the asynchronous get member there is no need to use the send member. Indeed the send member should only be used for reporting failed gets.

      use @dishes; is simply an error. I think you intended $Monks->use (@dishes);

      DESTROY @dishes; is a syntax error. Use @dishes = ();

      sleep until next $mealtime; is just hoplessley confused. The following would be appropriate:

      my $nextMealTime = $mealTime->next (); sleep (60) while (time < $nextMealTime);

      And finally, there is absolutly no need for a goto. you could use {...; redo;} instead, but there are many other options (see here).

      Very poor marks for this effort I'm affraid. Try harder next time, we know that you can do better than this.


      Perl is Huffman encoded by design.
        You need to lighten up.
      Huh?
      DESTROY @dishes;
      It's all Greek to me!