#
# Tao Te Ching
#
# By Lao Tzu
#
# Translated By Stephen Mitchel
+l
#
# Chapter 79
#
sub Failure { # Failure is an opportunity.
print 'Blame';} # If you blame someone else,
while (1){print 'Blame';} # there is no end to the blame.
#
sub Master { # Therefore the Master
my $Obligation++; # fulfills her own obligations
my $Mistakes--; # and corrects her own mistakes
+.
do {my $Needed++} until (my $Done); # She does what she needs to do
my $Others = 0;} # and demands nothing of others
+.
It's not the most eloquent way to put it, and it's still got some code structure instead simply flowing, but I've never tried this before. It's venting/jest.
#!/usr/bin/perl
use strict;
open (BLACKBOARD, "+>blackboard"); #look around
no strict;
use less 'time';
my $hand = 'reluctant'; @chalk = 'obsolete';
sub cheat {print BLACKBOARD "I will not use Perl in C class\n";}
until ($caught) {
use warnings;
&cheat;
$teacher_enters = int(rand(10));
if ($teacher_enters == 1) {
no warnings;
$caught = "red handed";
close BLACKBOARD;
delete @chalk[1,2,4];
} else {redo}
}
die "You are not to use Perl in C class, start the assignment again!";
I was stuck on something @work today and wanted to give up, but this struck me as I stared at the problem for the 100th time. Be gentle, it's my first time.
Why are the PerlMonks working?
They're hacking and golfing so fine.
And thinking and singing and smiling,
Cause seeking perl wisdom takes time!
Dear fellow monks!
Above is an exemplary output of my perl poetry generator, a small piece of code I wrote to learn about multi-dimensional arrays and Win32::OLE::Excel.
It is a port of a Pascal-program I created ~20 years ago ... any hint on how may I make it more "perlish"?
best regards Rata
#!/usr/bin/perl -w
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
my $Excel = Win32::OLE->new('Excel.Application', 'Quit');
my $sheet = $Excel->Workbooks->Open($ARGV[0])->Sheets->item("words");
+ # note to myself: add error handling here!
my @words;
foreach my $col('A'..'F')
{
my $row=1; my @list = (); my @value = ();
do { @value= $sheet->Range("$col".$row++)->{'Value'};
if (defined ($value[0])) { push (@list, $value[0]); }
} while(defined ($value[0]));
push (@words, \@list);
}
my $rhyme = int(rand( scalar(@{$words[4]}) ));
my $poem = $words[0][int(rand( scalar(@{$words[0]})))]." are ".$words[
+1][int(rand( scalar(@{$words[1]})))]." ".$words[2][int(rand( scalar(@
+{$words[2]})))]."?\n".
"They're ".$words[2][int(rand( scalar(@{$words[2]})))]." an
+d ".$words[2][int(rand( scalar(@{$words[2]})))]." ".$words[4][$rhyme]
+.".\n".
"And ".$words[2][int(rand( scalar(@{$words[2]})))]." and ".
+$words[2][int(rand( scalar(@{$words[2]})))]." and ".$words[2][int(ran
+d( scalar(@{$words[2]})))].",\n".
"Cause ".$words[2][int(rand( scalar(@{$words[2]})))]." ".$w
+ords[3][int(rand( scalar(@{$words[3]})))]." ".$words[5][$rhyme]."!\n"
+;
print ("$poem\n");
$Excel->Speech->speak($poem); # let us hear it!
exit 0;
#Provide the name of an Excel-file as parameter!
#Excel content (in a sheet called "words"):
#
# A B C D E F
#Why the PerlMonks coding perl wisdom in vain is pain
#Where the people hacking c-sharp like none is fun
#How the fanboys smiling unix so fine takes time
# great coders thinking posix
# small thinkerslearning shell scripts
# code monkeys asking java
# writing
# pasting
# ...