Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: JA(C|P)H

by jdalbec (Deacon)
on Mar 23, 2005 at 03:00 UTC ( [id://441672]=note: print w/replies, xml ) Need Help??


in reply to JA(C|P)H

This uses a few tricks to convert C into valid Perl. You can also do some tricks in the opposite direction using #define. Unfortunately you're limited by the fact that $ and (I think) @ are not valid characters in C code. However, gcc allows them so if you don't mind restricting the C code to gcc compilation you have more freedom.
#include <stdio.h> main() #ifdef __PERL__ ;sub main {} my $i; sub i:lvalue {$i} #endif { int i; for(i = 0; (i) < 10; (i)++){ printf("%d\n",i); } }

Replies are listed 'Best First'.
Re^2: JA(C|P)H
by ktross (Deacon) on Mar 23, 2005 at 13:35 UTC

    (++)

    Thanks, this is exactly the sort of thing I was looking for. I really like the fact that you defined main as a sub. That hadn't occured to me. Using #define had crossed my mind, but I decided not to use it this time.

    What really intreges me about this example is the line: 'sub i:lvalue {$i}'. To be honest, this is the first time I've come across an lvalue sub. I know what it is doing, but not exactly how it is doing it. Documentation here I come!

    Thanks again, you've raised some interesting possibilities.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-16 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found