http://qs321.pair.com?node_id=11105299

Downloaded:
https://github.com/gmatht/joshell/blob/master/scripts/perl2c%2B%2B.pl

Saved as hw.pl:
#!/usr/bin/perl my $h = "hello"; my $w = "world"; for (my $i = 0; $i < 3; $i++) { print "$h $w \n"; } my $n = 0; my $x = 100000000; for (my $i = 0; $i < $x; $i++) { $n++; } print "\n"; print "Counted to $n \n";
Typed:
perl perl2c++.pl < hw.pl | tee hw.cpp && g++ hw.cpp -o hw.o && time pe +rl hw.pl && time hw.o
Creating:
#include <iostream> int main(){ //!/usr/bin/perl std::string h("hello"); std::string w("world"); for (double i=0; i < 3; i++) { std::cout << "" << h << " " << w << " \n"; } double n=0; double x=100000000; for (double i=0; i < x; i++) { n++; } std::cout << "\n"; std::cout << "Counted to " << n << " \n"; return 0; }
Observed discrepancy:
perl	0m3.213s
c++	0m0.298s
Cool use for Perl, to learn a little C++!

Replies are listed 'Best First'.
Re: perl2c++.pl (I know Kung Fu)
by Discipulus (Canon) on Aug 30, 2019 at 11:15 UTC
    First line by the author, after shebang:

    > # A horrible prototype of a Perl to C++ compiler.

    But interesting ;)

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.