LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Where exactly Perl & C/C++ are getting different and unique compare to each other..? (https://www.linuxquestions.org/questions/programming-9/where-exactly-perl-and-c-c-are-getting-different-and-unique-compare-to-each-other-739925/)

deepak_p86 07-14-2009 02:19 AM

Where exactly Perl & C/C++ are getting different and unique compare to each other..?
 
Hi Friends,

I am new to perl, and I want to understand the importance of perl compare to C/C++. I want input from your experience & Knowledge.

Please share the scenario's or requirement where perl would be more preferable then C and also vice-versa.

I know its broad subject. But your single input will be helpful to everyone.

Thanks,
Deepak

sundialsvcs 07-14-2009 08:39 AM

C/C++ is a great language for writing the Perl compiler/interpreter. In fact, it's the language that is used. (C/C++ was even used to write itself, but that's another story...)

It's also a good language for writing certain low-level portions of some of the many CPAN modules.

"Aye, here's the rub..." The low-level portions, not all of them. The parts that need to run very fast. In the proverbial "80/20 rule," C/C++ is used for "the crucial 20% of the code that is running 80% of the time." The messy inner workings of "a hash," for example. Memory management and garbage-collection. Or references. The rocket-science stuff... but only the rocket-science stuff.

For "all the rest of it," you simply write it in Perl, knowing that by so doing you are happily taking advantage of a very large amount of well-tested C/C++ code that you call "Perl, itself." In a single line of Perl code you can do many complicated things that would ... and in fact, that did ... take "pages and pages of clever and tricky C/C++ code" to specify. That clever, tricky code is part of Perl itself, and so you can take full advantage of someone else's cleverness while completely ignoring it. :)

Referring once again to the "80/20 rule," nearly all of the code in a typical application is boring ... uninteresting ... and, time-wise, rarely used. The time that needs to be saved is your time, not the computer's. ("At 10 billion ops per second, no one can hear you scream.") What you need, then, is a very well-written power tool that allows you to be expressive ... and that's what Perl is. Perl is a lever.

What makes Perl particularly useful and impressive is... the CPAN library. Your work becomes vastly more efficient when you can leverage someone else's complete, well-tested package to do some task... which Perl allows you to do particularly easily.

This analogy can of course be extended to any of the other myriad scripting-languages that Unix/Linux supports: PHP, Python, Ruby, Scheme, various Visual Basic knock-offs, etc. etc. (They, too, have their analog to CPAN.)

Sergei Steshenko 07-14-2009 10:48 AM

And, in fact, one can essentially mix Perl and "C" code using Inline::C module

http://search.cpan.org/~sisyphus/Inline-0.45/C/C.pod

- I've implemented pretty serious stuff using it.

Furthermore, in my case Perl is used to autogenerate part of the needed "C" code.

deepak_p86 07-14-2009 11:14 PM

Thanks a lot for your valuable input.

Wim Sturkenboom 07-14-2009 11:52 PM

Quote:

Originally Posted by sundialsvcs (Post 3607229)
...In fact, it's the language that is used. (C/C++ was even used to write itself, but that's another story...)

Did they already solve the chicken-and-egg problem on those days :scratch: Why am I still running into it :)


All times are GMT -5. The time now is 09:32 AM.