### myQuestion.pl

by Falkkin (Chaplain)
 on Mar 24, 2000 at 00:48 UTC ( #6000=poem: print w/replies, xml ) Need Help??

```my (\$question, \$to_be, \$asleep); # version 0.1
my \$author = "Colin McMillen";
my \$apologies_to = "William Shakespeare";

my \$to_be = 1;

while (\$to_be || (!\$to_be)) {
\$question = "that";
if (suffer(\$slings && \$arrows_of_outrageous_fortune)
or
(take_arms_against(\$sea_of_troubles) && by_opposing() eq "end
+them")) {
do {
\$to_be = 0;
\$asleep = "no more";
die "We end the heart-ache, and the thousand".
" natural shocks that flesh is heir to";
} while ("'tis a consumation devoutly to be wish'd.");
}
}

sub suffer {
return true;
}
sub take_arms_against {
return true;
}
sub by_opposing {
return "end them";
}

# Output:
# We end the heart-ache, and the thousand natural shocks that flesh is heir to at myQuestion.pl line 15.

Replies are listed 'Best First'.
RE: myQuestion.pl
by Anonymous Monk on Mar 30, 2000 at 05:56 UTC
that is classic! kudos! -grndzero
RE: myQuestion.pl
by hedgehog (Initiate) on Apr 11, 2000 at 17:14 UTC
I love the soliloque. Just one thing though - it should be:
```&& by_opposing() eq "end them"))

Philosophical/religious question:

Given the tiny number of failure cases, should Perl really have two sets of comparison/equality operators?
If Perl made a distinction between numerals in scalars and characters in scalars, yes. As the typing system is weak (that is, a combination of internal Perl magic and context determine which operation is more appropriate), it's helpful to be able to specify explicitly which kind of comparison is desired.

That's also why you'll see empty lists and the keyword scalar sometimes -- just a way of being sure that the operation has the desired effect by enforcing context and giving hints to the internal magic.

(Now things like && and and are merely syntactic sugar designed to make Perl Poetry more readable. Right. :)

'and' and 'or' are not merely the syntactic sugar (1) equivalents of && and || - they have a lower precedence. I prefer using && and ||, but 'and' and 'or' come in quite handy occasionally.

(1) A lovely phrase. I wouldn't mind if perl had more for-foreach like things, just so I could sling the phrase around more often. :)

By two sets, do you mean "eq" and "==", "gt" and ">", etc.?

A string comparison is much different than a numeric comparison. Look:

```\$string = "556foo";
\$num = 556;

print "string comparison equal" if \$string eq \$num;
print "num comparison equal" if \$string == \$num;
The result?
```num comparison equal
So if these are the sets of operators that you're referring to, they're definitely not redundant; you couldn't simply drop one set and have the same functionality as you do now.

Are you proposing that we differentiate between string and numeric comparisons in some other way than the operators?

Which two sets? || and 'or', or perhaps <=> and 'cmp', or even > and 'gt'? None are redundant, as far as I am concerned.

Re: myQuestion.pl
by arturo (Vicar) on Apr 17, 2001 at 20:06 UTC

Hm ... thinking back, I'm not clear how one might write this one in an OO fashion ...

```package Action;

sub new {
my \$class = shift;
my \$self = {};
bless \$class, \$self;
\$self;
}

# other methods

sub set_nobility {
if (\$self->{type} eq 'suffer') {

\$self->{nobility} = \$self->{acted_upon) eq 'slings and arrows of out
+rageous fortune' ? 1 : .5;
}
if (\$self->{type}  eq 'take arms against') {
\$self->{nobility} = \$self->{acted_upon) eq 'a sea of troubles' ? .9
+8 : .2;
}
}

sub nobility {
return \$self->{nobility};
}

Putting it to use is left as an exercise for the reader ... erm, author.

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Create A New User
Node Status?
node history
Node Type: poem [id://6000]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-08-24 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (367 votes). Check out past polls.

Notices?