Dont even bother wasting your time reading over my node here. I was unaware that it had been done so many times before. Sorry! :(
OK, I was recently given this problem. Its not too hard, but its a fun little problem to figure out. The goal was to make a perl script that prints out a perl script, that prints out a perl script, and on and on. The trick was that it couldn't read itself in (so no using open(M,$0);). Well anyways, the following is the code I wrote to solve it:
$dna = '$dna = CAC;B%t = (C65C,"$dna",C66C,"\n",C67C,"C");Bfor($i=0;$i
+<153;$i++)B{$q = ord(substr($dna,$i,1));Bif ($t{$q}) {print $t{$q};}B
+else {print chr($q);}}';
%t = ('65',"$dna",'66',"\n",'67',"'");
for($i=0;$i<153;$i++)
{$q = ord(substr($dna,$i,1));
if ($t{$q}) {print $t{$q};}
else {print chr($q);}}
I know its not the greatest, but I like to hear other people's suggestions on how to make it shorter.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.