Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl is C

by Ovid (Cardinal)
on Dec 20, 2001 at 02:49 UTC ( [id://133308]=obfuscated: print w/replies, xml ) Need Help??

Not sure where to put this as it's not obfuscated, but this is my first attempt at writing a program that parses in two different languages. Specifically, this Perl program compiles as C code under Cygwin with:

gcc hel2.c -o hel2 -Wall -ansi

I'm embarrassed by all of the cheap preprocessor instructions in there. It seems like a cop-out.

#include <stdio.h> #ifdef _FSTDIO #define $i i #define sub #define main int i; int main sub main() { #else sub main(); #endif for ($i=0;$i<5;$i++) { printf("Just another Perl hacker,\n"); } return(0); } #ifndef _FSTDIO main(); #endif

Okay, not very good. Shoot me :) Since I did specify -ansi on the command line of the C compiler, I expect that this will work on any C compiler.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re (tilly) 1: Perl is C
by tilly (Archbishop) on Dec 20, 2001 at 08:07 UTC
    Indeed, you only need one pre-processor instruction, and can make it look like a routine C exercise while you are at it:
    #include <stdio.h> /* Just a simple finger exercise */ #define eval int main() /* To demonstrate the pre-processor */ eval { printf("Hello world\n"); return (0); }
(jcwren) Re: Perl is C
by jcwren (Prior) on Dec 20, 2001 at 02:59 UTC

    You realize, of course, what you've started...

    I couldn't get the 'Perl is COBOL' version to work, tho.

    --Chris

    e-mail jcwren

Re: Perl is C
by spm (Acolyte) on Mar 05, 2002 at 15:21 UTC
    A few really cool things are available in GCC; one is allowing dollar signs before all variable names (one down). After that, most things can be fixed by making one
    typedef char* my;
    and then doing "my $foo;". Next, overload the ++ and -- operators... ohh, you get my drift :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found