So let's say you are on a *nix machine and you need an application that echos what you type. And let's further say that you want to use perl, python, ruby and shell to do it. I bring you convoluted echo. A perl script the writes and executes a python script that's and executes a ruby script which writes and executes a shell script to echo your command line arguments.
Happy Memorial Day
#!/usr/bin/perl
my $echo = q{};
open my $py, '>', 'ce.py' or die "Cannot open ce.py: $!\n";
$py->print("#!/usr/bin/python\n\n");
$py->print("import os\n\n");
$py->print("fo = open(\"ce.rb\",\"w\")\n\n");
$py->print("fo.write(\"#!/usr/bin/ruby\\n\")\n");
$py->print("fo.write(\"out_file = File.new(\\\"ce.sh\\\", \\\"w\\\
+")\\n\")\n");
$py->print(q{fo.write("out_file.puts(\"#!/bin/sh\\n\\necho $*\\n\\
+")\n")});
$py->print("\n");
$py->print(q{fo.write("out_file.close\n\n")});
$py->print("\n");
$py->print("\n");
foreach my $a (@ARGV) {
$echo .= " ".$a;
# $py->print( " $a ");
}
$py->print(q{fo.write("system(\"/bin/sh ce.sh });
$py->print(" $echo ");
$py->print(q{\")\n")});
$py->print("\nfo.close()\n");
$py->print("os.system(\"/usr/bin/ruby ce.rb\")\n");
close $py;
system("/usr/bin/python ce.py");
--
“For the Present is the point at which time touches eternity.” - CS Lewis
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|