Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

perl2c++.pl (I know Kung Fu)

by Anonymous Monk
on Aug 30, 2019 at 09:25 UTC ( #11105299=CUFP: print w/replies, xml ) Need Help??

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 (Abbot) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://11105299]
Approved by Discipulus
Front-paged by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2020-04-08 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (45 votes). Check out past polls.

    Notices?