use Perl Log In
TMTOWTDI in action
CanSpice writes "The company I work for has just come up with voluntary lunchtime seminars to be put on by fellow employees. I figured that an hour on Perl and its informal slogan "There's more than one way to do it" would be a fine topic. So, I throw a challenge out to all the Perl programmers out there: how would you write a Perl program that would add one plus one?
I've seen this before, but have no idea where. I'm looking for fresh solutions as well, solutions that incorporate potential new features of Perl 6, along with the old diehards (bit mangling, regexps, blatant misuse of special variables, etc.)."
The classic 163-line Perl program to add 1 + 1 is mjd's Perl and the Lambda-Calculus.
Lunchtime seminars can be an interesting way to share ideas
about Perl in the office. If you have a story, please
tell us about it.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.

TIMTOWTDI in action and $A++ (Score:1)
use the award-winning Inline module (Score:1)
int one_plus_one() {
return 1 + 1;
}
EOC
print one_plus_one();
We are Perl. Your table will be assimilated. Surrender your beer. Resistance is futile.
pid nastiness (Score:1)
Ideas for solutions (Score:1)
Write the binary logic by hand using and (&), or (|), xor (^), shifts (<<, and >>), and simple loops.
Go wacky with Roman numerals.
Other wacky code snippets:
"1+"+"+1"
"1+1"+"1+1"
$\=$/;"1+1"=~/(.)[+](.)/; print $++$+;
print print."+".print."=".((print)+(print))."\n";
Gotta love recursion (Score:1)
my $one_plus_one = sum(ceil(rand), cos());
sub sum {
@_ && (shift)- -sum(@_);
}
btw - this code will fail to produce a correct answer every once in a while
store the data in the program (Score:1)
Oh, for a CODE tag like on PerlMonks...
Re:store the data in the program (Score:1)
CODE? You mean like this?
my $val;
sysseek(DATA, -10, 2);
sysread(DATA, $val, 1);
$val += $val;
print "$val\n";
1
__END__
Re:store the data in the program (Score:1)
pudge, you're my hero once again.