Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Quine like self-rewriting program in perl
eval($code=q{
# Quine like self-rewriting program
# 1st : $ perl quine.pl > a1.pl
# repeat : $ perl a1.pl > a2.pl ; cat a2.pl ; cp a2.pl a1.pl
$str="
XXXXXXXXXX
A
XXXXXXXXXX
";
@arr = split('XXXXXXXXXX',$code);
if($arr[1] =~ /\sA\s$/){$arr[1] = "\nAp\n"}
elsif($arr[1] =~ /\sAp\s$/){$arr[1] = "\nApr\n"}
elsif($arr[1] =~ /\sApr\s$/){$arr[1] = "\nApri\n"}
elsif($arr[1] =~ /\sApri\s$/){$arr[1] = "\nApril\n"}
elsif($arr[1] =~ /\sApril\s$/){$arr[1] = "\nApril_\n"}
elsif($arr[1] =~ /\sApril_\s$/){$arr[1] = "\nApril_F\n"}
elsif($arr[1] =~ /\sApril_F\s$/){$arr[1] = "\nApril_Fo\n"}
elsif($arr[1] =~ /\sApril_Fo\s$/){$arr[1] = "\nApril_Foo\n"}
elsif($arr[1] =~ /\sApril_Foo\s$/){$arr[1] = "\nApril_Fool\n"}
$code = join('XXXXXXXXXX',@arr);
print"eval(\$code=q{$code})\n"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment