Perl-Sensitive Sunglasses | |
PerlMonks |
Apple Perl Quineby usemodperl (Beadle) |
on Jun 20, 2018 at 02:09 UTC ( [id://1216984]=CUFP: print w/replies, xml ) | Need Help?? |
This perl code compiles and runs an apple mac app
that decompiles and prints its own applescript
source code:
Easier to read: perl -Mautodie -we '$app="ApplePerlQuine\@perlmonks.org.app"; die"not apple mac"unless${^O}eq"darwin"; open$f,"|-","osacompile -o $app"; print$f qq~ set myPATH to path to me as string\n set myPATH to myPATH & "Contents:Resources:Scripts:main.scpt"\n set myPATH to do shell script"echo " & myPATH & " | tr : / | sed -E \x27s/Macintosh HD//\x27"\n display dialog (do shell script ("osadecompile " & myPATH)) with title "$app" buttons {"Use Perl!"} default button 1\n ~; close$f; system("open $app")'Easier to understand: 1. Perl setup: perl -Mautodie -we '$app = "ApplePerlQuine\@perlmonks.org.app"; die "not apple mac" unless ${^O} eq "darwin";2. Open pipe to applescript compiler and print: open $f, "|-", "osacompile -o $app"; print$f qq~3. Set applescript variable to the app path: set myPATH to path to me as string\n4. Append path of compiled source (inside the app): set myPATH to myPATH & "Contents:Resources:Scripts:main.scpt"\n5. Use shell to manipulate the path: set myPATH to do shell script"6. Change applescript variable with tr and sed: echo " & myPATH & " | tr : / | sed -E \x27s/Macintosh HD//\x27"\n7. Decompile app and display source code: display dialog (do shell script ("osadecompile " & myPATH)) with title "$app" buttons {"Use Perl!"} default button 1\n8. Back to perl, end print, close pipe, open app: ~; close$f; system("open $app")'Summary: lines 1-2 and 8 use perl to write the app with applescript in lines 3-7. As a script:
This one prints itself entirely, including the perl:
STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS!—CPAN
Back to
Cool Uses for Perl
|
|