Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

BASIC hajp

by kschwab (Vicar)
on Jan 18, 2001 at 22:27 UTC ( [id://52808]=obfuscated: print w/replies, xml ) Need Help??

Not all that obfuscated, but how could I resist the "Hack another just perler" anagram ?

Runs under both BASIC (tested with yabasic-2.66) and perl. Neither "-w" or "use strict;" is very happy with it though :)

REM ;for(<DATA>){ REM ; chomp;s;\c0\$;\$\c0;;s; ^\d0;;x; REM ; s;(\w)\w+\$\(;\1\(;x;/(\d+),(\d+)/||{$;=$1,/(\d)/}; REM ; $2?{$==$1-1,$:=$2}:{$:=$1,$==0,$;eq"r"&&{$=-=$:}}; REM ; s;$1,*\d*;$=,$:;;$:&&s;\w\(;substr\(;;eval;} REM ; print "\n"; REM ;__DATA__ 10 p$="hack another just perler" 20 print mid$(p$,14,4); 30 print mid$(p$,5,8); 40 print mid$(p$,18,5)," "; 50 print left$(p$,4); 60 print right$(p$,2)
Update: Based on this reply from BooK, here's something a little closer to a polyglot:

REM ;$_=<<REM; sub japh() REM REM ; $_.="{" . <<'REM ;'; print "Just another Perl hacker\n"; REM ; REM ;$_.="}";eval;<<'REM'; end sub REM japh()

Replies are listed 'Best First'.
Re: BASIC hajp
by BooK (Curate) on Jan 19, 2001 at 00:50 UTC

    Basically, you wrote it so BASIC_COMMENT is PERL_CODE while BASIC_CODE is PERL_COMMENT... Both parts are distinct: remove the Perl code and the BASIC works pretty well.

    This is the first step into polyglots, but don't stop here.

    Next, you can try using the variable q$ in BASIC, which will allow you to hide a little BASIC into a Perl quoted-string... Then you begin to intermix the two languages. That is where the real fun part begins.

    Until you reach a point where every part of the code is essential. When you're stuck with your code, and it's just... beautyful. Like a work by M. C. Escher.

    Of all aspects of writing polyglots, this is the best, ever... (soooorry, couldn't help)

      Well, sort of. The BASIC can stand alone, but the Perl is something of a fragile/one-off/single purpose BASIC interpreter. So, the BASIC works without the Perl, but the Perl doesn't work without the BASIC.

      I like the q$ idea...perhaps I can get more than 1/2 a polyglot next time.

      Thanks for the feedback...

      Update: I added something a bit closer to a polygot on the original node. Thanks BooK !

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://52808]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found