Slashdot Mirror


Extending and Embedding Perl

ggoebel writes "Extending and Embedding Perl is, as it boldly states on the cover, 'The definitive guide to XS, embedding, and the Perl internals.' This book is well organized and information dense. One could spend days sifting through the available perlapi, perlcall, perlembed, perlguts perlxs, perlxstut, and h2xs documentation. After which you'll probably understand very well references to nethack's 'You are in a maze of twisty little passages all alike.' Or you could get yourself a copy of this book and find your way out of the maze." Read on for the rest of ggoebel's review. Extending and Embedding Perl author Tim Jenness and Simon Cozens pages 384 publisher Manning (August 2002) rating 9 of 10 reviewer ggoebel ISBN 1930110820 summary The definitive guide to XS, embedding, and the Perl internals

Most of the available documentation on extending and embedding perl is written from the prospective of the core perl developers for core perl developers. This book is written for advanced Perl programmers who for whatever reason need or wish to peer into that netherworld between Perl, C, and the glue that interfaces Perl with other languages. It is a deliberate thorough guide led by authors that are both extremely knowledgeable and also capable of communicating that knowledge.

While it would greatly reduce the learning curve, no prior knowledge of C is required to read this book. This is a surprising claim and while it won't be easy, this reader is proof that someone with little true knowledge of C can in fact read and for the most part comprehend what the authors wish to convey.

There are clearly areas for improvement. Things like NULL being used throughout chapter 3, only to finally be defined later in a footnote in chapter 4. And other cases of terms being used before they are explained. Things that leave the reader juggling unnecessarily until the information is provided that lets understanding fall into place. But for the most part, if you are a competent juggler and are patient your questions will eventually be answered. You won't walk away a C programmer, but you will learn enough to solve the problems which led you to consider reading this book in the first place.

One thing I liked very much about the layout of the book is how it switches back between presenting sections on C programming and Perl. The authors revisit C each time it is necessary to understand the next Perl internals topic. Those that are learning C or need the review receive the relevant information just before it is required.

Over the course of the book, you'll learn about interfacing from Perl to C and C back to Perl. For those that must plug references to Tolkien in things Perl... you can go back and rephrase that into an appropriate reference to Bilbo's book "There and Back Again". You'll also learn the perl api, data structures for core variable types, and how to work with scalars, arrays, hashes, strings, regular expressions, file handles, typeglobs, typemaps, objects, callbacks and PDL with C and C++. And there is even mention of working with Fortran, Java, and more esoteric alternatives.

The book finishes with an in depth look at Perl internals: the parser, tokenizer, op code trees, execution, and compiler. And closes with a discussion of the Perl development process: How it may be monitored and participated in.

What's missing? Detailed coverage of the I/O subsystem and the regular expression engine. I.e., topics which might themselves make for a good book. There was also light coverage on things like scratchpads. There were times while reading when I didn't know whether the issue being discussed was fully covered or curtailed. But you will certainly find better coverage of the issues in this book than elsewhere. This is an impressive book. I hope it will greatly influence the way Perl6 internals are documented.

You can purchase Extending and Embedding Perl from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

124 comments

  1. M$! by Anonymous Coward · · Score: 0, Funny

    Will write "embracing and extending PEARL". Boy! I can't WAIT for that one to come out!

  2. You are likely to be eaten by a grue by Dynedain · · Score: 4, Funny

    After which you'll probably understand very well references to nethack's 'You are in a maze of twisty little passages all alike.'

    Funny, I remember that exact phrase from Zork.

    --
    I'm out of my mind right now, but feel free to leave a message.....
    1. Re:You are likely to be eaten by a grue by tuffy · · Score: 1
      Funny, I remember that exact phrase from Zork.

      Heck, Nethack didn't have *any* room descriptions, since it's traditionally all ASCII art.

      --

      Ita erat quando hic adveni.

    2. Re:You are likely to be eaten by a grue by drf5n · · Score: 1

      Funny, I exactly remember that phrase from Adventure

    3. Re:You are likely to be eaten by a grue by Anonymous Coward · · Score: 0

      I thought it was Wumpus.

    4. Re:You are likely to be eaten by a grue by hoggoth · · Score: 4, Informative

      It's not from Zork. It's from the Original Adventure (Colossal Cave). If it's in Zork, it's as a homage to the Original Adventure.

      --
      - For the complete works of Shakespeare: cat /dev/random (may take some time)
    5. Re:You are likely to be eaten by a grue by gray+peter · · Score: 1
      XYZZY

      Yep. It's from Adventure. I remember it well...

      --
      May no camel spit in your yogurt soup.
    6. Re:You are likely to be eaten by a grue by Anonymous Coward · · Score: 0

      > Heck, Nethack didn't have *any* room descriptions, since it's traditionally all ASCII art.

      Nethack is still alive and well (you insensitvie clod). Second, it does. "You enter an opulent throne room!" "It looks rather wet down here."

    7. Re:You are likely to be eaten by a grue by Pr3d4t0r · · Score: 1

      Yep, it's also in Zork along with XYZZY, plugh, and possibly other references.

      http://www.bf.rmit.edu.au/~fayep/Zork~fayep/Zork/l ingo.html

  3. I must be silly by Anonymous Coward · · Score: 0

    Does anyone else confuse CPAN with CSPAN?

    I cannot be the only one

    1. Re:I must be silly by cruppel · · Score: 1

      I do it daily.

    2. Re:I must be silly by ewall · · Score: 0, Offtopic

      Sadly, I don't get cable TV... (Heh, a CPAN show would be a great idea: sort of like HSN, but no prices!)

      --
      Karma Police, come arrest this man...
  4. misread that title :) by Photon01 · · Score: 4, Funny

    misread that title at first glance, was dreading to see what microsoft had done to perl :)

    1. Re:misread that title :) by glwtta · · Score: 1

      Don't even joke about that! Tracking down Gates and Balmer (with a machete on-hand) would be really difficult to fit into my schedule, but would have to be done, should MS ever touch Perl (or perl, for that matter) in any manner.

      --
      sic transit gloria mundi
    2. Re:misread that title :) by Anonymous Coward · · Score: 0
      but would have to be done, should MS ever touch Perl (or perl, for that matter) in any manner.

      You can be certain that Microsoft doesn't want to touch Perl. Having programmed in Perl, it's hard to blame them. I don't want to touch Perl either...

    3. Re:misread that title :) by Istealmymusic · · Score: 1

      In similar vain to Visual C++ and Visual Basic, we already have Visual Perl and Visual Python [1].

      [1] But they aren't written by Microsoft.

      --
      "The lesson to be learned is not to take the comments on slashdot too literally." --Vinnie Falco, BearShare
    4. Re:misread that title :) by Anonymous Coward · · Score: 0

      Tracking down Gates and Balmer (with a machete on-hand) would be really difficult to fit into my schedule, but would have to be done, should MS ever touch Perl (or perl, for that matter) in any manner.

      Yes! Damn them to hell for funding Activestate's Win32 perl port. It has been a plot all along.

  5. Correct: This is a Zork reference. by Anonymous Coward · · Score: 0

    Nice try at the submitter trying to be a dork though.

  6. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    hmmm

    methinks if you can't understand what your wrote in the past, your time would be better spend learning how to write good perl than bitching about how you can't...

    just a thought

    _g-)

  7. Or just use Python by Anonymous Coward · · Score: 0, Troll

    To extend/embed Perl you apparently need a book. For the same task with Python, simply look up the fine documentation on their web page, and you're ready do go in less than an hour.

    Let the flames come...

    1. Re:Or just use Python by RLiegh · · Score: 1

      Slashdot runs on PERL. Python may indeed be better documented, but PERL is more suited to larger projects and it's more readily available than is Python.
      Just IME and IMHO.

    2. Re:Or just use Python by glwtta · · Score: 1
      Slashdot runs on PERL

      Hm I see most scripts have a .pl extension - does slashdot use Acme::Inline::PERL then? :)

      --
      sic transit gloria mundi
    3. Re:Or just use Python by Anonymous Coward · · Score: 0

      To extend/embed Perl you apparently need a book.

      So how have all the people who have already extended Perl done so?
    4. Re:Or just use Python by be-fan · · Score: 1

      Python is by far more suitable for larger projects. Python code is much more readable and the syntax is much more regular. Python is more a high-level take on Java than a scripting language.

      --
      A deep unwavering belief is a sure sign you're missing something...
  8. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    Cheap php hack! STFU.

  9. This is a dead end by Ars-Fartsica · · Score: 3, Informative
    One of the key reasons the Perl 6 project is taking such radical steps in remaking the language is precisely because extending and embedding Perl 5 is HELL.

    Investing in this book and this knowledge at this point is practically a dead-end, as most of the annoying kludges will end with Perl 5.

    Only invest in this book and this knowledge if there is a project you are working on that requires embedding or exteninding perl now. Otherwise wait for the sane cleaned-up world of Perl 6.

    1. Re:This is a dead end by Rick+the+Red · · Score: 2, Funny
      Otherwise wait for the sane cleaned-up world of Perl 6.
      Coming when, exactly? This book could be useful for years.
      --
      If all this should have a reason, we would be the last to know.
    2. Re:This is a dead end by hondo77 · · Score: 1

      Perl 6 is not a big switch, such that when it is thrown/released we will be doing all Perl development with it and dumping 5. Perl 5 development is going to continue for a long time, making this book far from a dead-end.

      --
      I live ze unknown. I love ze unknown. I am ze unknown.
    3. Re:This is a dead end by duffbeer703 · · Score: 1, Flamebait

      How is this going to happen? The core perl developers are broke and nobody is funding them!

      Plus, Perl 6 is a totally new language. If I want to learn a new language, I'll bite the bullet and learn Python.

      --
      Conformity is the jailer of freedom and enemy of growth. -JFK
    4. Re:This is a dead end by Anonymous Coward · · Score: 1, Informative

      The core perl developers are broke and nobody is funding them!

      Nevermind Perl6, its Parrot VM team is directionless and hasn't produced anything useful in two years. Parrot still has no exceptions, no thread support, no external module loading and no object support. But there's a real-life metric it excels at: MOPS. Parrot can decrement an integer in a loop faster than any other interpretor. They should be proud.

      Here's something to put it into perspective: Mono and Parrot development started at the same time.

    5. Re:This is a dead end by bcrowell · · Score: 1

      Plus, Perl 6 is a totally new language. If I want to learn a new language, I'll bite the bullet and learn Python.
      Perl 6 will be backward-compatible with perl 5. The interpreter will automatically recognize whether your module was written in Perl 5 or Perl 6. You'll be able to take advantage of the improved implementation of the language without having to learn anything new.

    6. Re:This is a dead end by bcrowell · · Score: 1

      extending and embedding Perl 5 is HELL.
      It's not just hell for developers, it's hell for users, too. For instance, if you upgrade from Perl 5.6 to Perl 5.8, you have to recompile every single C library that your Perl code links too. Ouch! Try explaining that to your typical end-user.

    7. Re:This is a dead end by duffbeer703 · · Score: 1

      If I have perl 5 code and years of experience writing it, what is going to make me want to re-code everything when all my old stuff works anyway?

      perl 6 is a solution without a problem -- which is why commercial sponsors aren't sponsoring it.

      --
      Conformity is the jailer of freedom and enemy of growth. -JFK
    8. Re:This is a dead end by Koschei · · Score: 2, Informative

      Of course, Mono is just working to implement a preexisting VM. Parrot has grander aims.

      Here, why not learn something.

      --
      -- koschei
    9. Re:This is a dead end by Koschei · · Score: 1

      Ok. Let's try:

      "If you upgrade from 5.6 to 5.8, you have to recompile your C based Perl modules."

      Fairly simple. Making a snapshot bundle and installing said bundle is also trivial.

      Depending on how your previous Perls were compiled, you may or may not have had to do this previously anyway. On the bright side, it also means that users will probably have more up to date versions of modules rather than whatever version existed 3 years ago (5.6.0) or longer (5.005 was 5 years ago). Modules can change a lot in that time. As can the language itself.

      --
      -- koschei
    10. Re:This is a dead end by bcrowell · · Score: 1

      If I have perl 5 code and years of experience writing it, what is going to make me want to re-code everything when all my old stuff works anyway?
      You don't have to re-code. Please read my previous post more carefully.

    11. Re:This is a dead end by mkcmkc · · Score: 1
      Perl 6 will be backward-compatible with perl 5.
      If true, this would cancel out the best advantage of Perl 6, which would be to rid the language of all of those incomprehensible syntactic quirks that Perl 5 has accreted. The Perl book is already over 1000 pages long--will it be 2000 pages for Perl 6?

      --Mike

      --
      "Not an actor, but he plays one on TV."
    12. Re:This is a dead end by duffbeer703 · · Score: 1

      I don't think that I was clear enough.

      If I can just run everything from Perl 5 in Perl 6, why would I want to write code in Perl 6? (that won't work on the millions of currently deployed machines with perl 5 already installed)

      The cool thing about Perl 6 is that you get a commmon runtime engine that can run multiple language on multiple platforms. That's neato.

      But why a new language with new syntax, bugs and oddities?

      --
      Conformity is the jailer of freedom and enemy of growth. -JFK
    13. Re:This is a dead end by Anonymous Coward · · Score: 0

      Shut yer yap. No one cares about this non-working VM.

  10. NULL? by Anonymous Coward · · Score: 2, Insightful

    >Things like NULL being used throughout chapter 3, only to finally be defined later in a footnote in chapter 4.

    You said yourself that this book is intended for experienced programmers. If you don't know what a NULL is as well as the implications, and are a programmer, you are in deep doo doo. You definitely cannot be considered to be an advanced programmer. I am suprised this book even defines NULL.

    However, I have seen a lot of programmers that have trouble and bugs related to NULL values ... of course I tend to immediately not listen to anything they say anymore, but some have produced code that does work. I hate to imagine what else they don't know... especially about other important stuff like security and database efficiency.

    l8,
    AC

  11. Re:Hmm, let's see ... by cmburns69 · · Score: 5, Interesting

    You're dissing perl for being quick and dirty, but just because you can use a shortcut, doesn't mean you have to. I can code with perl and have it come out looking as clean as Pascal (or even *gulp* Java).

    Things can be done in other "structured" languages that would be as unreadable as the most obfuscated perl code. Being able to read your code 9 months from now is more a function of programmer discipline than the language used.

    This game was written in perl, when I was learning, 5 years ago, and because I used good design and comments, I can still read and update the code.

    An online Starcraft RPG? Only at

    --
    Online Starcraft RPG? At
    Dietary fiber is like asynchronous IO-- Non-blocking!
  12. Re:Hmm, let's see ... by B3ryllium · · Score: 2, Insightful

    use Perl or die();

    I use PHP for web interfaces, Perl for unix scripts, and C++ for ... well ... Windows crap. Gawd I hate MFC. But that's another story.

    PHP's function handling has a certain ellegance that Perl seems to totally and completely lack.

    function MyFunction($line1, $line2)
    {
    print $line1 . "\n" . $line2;
    }

    vs.

    sub MyFunction {
    my ($line1, $line2) = @_;
    print $line1 . "\n" . $line2;
    }

    People argue with me endlessly that perl's method "isn't a hassle". I use Eclipse to edit PHP, and thanks to an add-on, whenever I'm working on a PHP page, I have instant access to every function and object in that file, complete with the function prototype - at a glance, I can see what any given function needs as input. And, given the fact that all of those variables in the prototype are named, one can indirectly provide information on what the whole function is intended to do, if the function name and variable names are written properly.

    I suppose there's always the alternative.

    sub MyPerlFunctionWhatTakesTwoScalarVariablesAndPrints ThemOnSeparateLines {}

    But like I said, I prefer PHP's method.

  13. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    Take that troll and stick it up your ass. This is more of an issue with your programming skills than it is with the actual language. Perl allows for freedom. A lot freedom in the way you wish to, or wish not to control the syntax/structure of the project. Although for you it seems that you do not have the skill in which to grok the language and produce coherent code. Again this is not a problem with the language.

  14. Re:Hmm, let's see ... by B3ryllium · · Score: 1

    s/ellegance/elegance/ :)

  15. Re:Hmm, let's see ... by nomadicGeek · · Score: 1

    I felt exactly the same way when I started to use Perl. Like everything else it just takes getting used to. After a while you have screwed your brain up and it all starts to make sense. You look at the goofy syntax and it means something to you. Then the syntax actually starts to feel elegant.

    The funny thing is that I now wish the other languages that I use had some of the Perl shortcuts in them. It really speeds things up.

  16. Re:Hmm, let's see ... by B3ryllium · · Score: 1

    Argh ... perl comments ... I don't want hashed comments, I want C++-style comments! But that's nitpicking :)

    You have a very valid point :) It's just far far easier to obfuscate perl than with other common languages. At least in my own limited experience.

    Have you ever played Perl Golf? Looking at the answers to that competition makes my brain cry. But then, I suppose that's the point :)

    Has anyone ever made a Perl IDE? And I don't mean vi ... I might be interested in using some sort of VisualStudio-style IDE, if one existed. Maybe as an add-on to Eclipse? I'm very big about function prototypes and having "outlined" displays of code. It better fits my compulsion towards laziness.

  17. Re:Hmm, let's see ... by vadim_t · · Score: 1

    Yeah, Perl's argument handling is a bit messy. But it's completely flexible as well. You can have named arguments even though there's no special support for them, for example. And it's easy to write generic code to say, log all the arguments passed to a function.

  18. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    sub crap1 { print join "\n", @_ }
    sub crap2 { print $_, "\n" for @_ }
    sub crap3 { print "You're an idiot!" }

    Yes, Perl's argument handling functionality leaves something to be desired (hint: it's fucked) but if I were to start looking for "better" languages to use (hint: a language I can use for something other than web shite) I would look yonder Python.

  19. Guide to doing it the hard way? by Andy+Dodd · · Score: 3, Informative

    Or does the book cover easier ways to embed C into Perl, such as SWIG.

    SWIG rocks. SWIG is your friend. I'll agree that extending Perl by embedding C is hell and the documentation sucks, but SWIG makes it all (relatively) easy. With SWIG all you have to do is be careful about data types. (Mainly, you can't directly pass a Perl array to C code, you have to convert it into a C array first. How to handle situations like this with SWIG is well documented.)

    I spent five days trying to figure out how to embed some C functions into Perl. Then I discovered SWIG and was up and running in 3-4 hours.

    --
    retrorocket.o not found, launch anyway?
    1. Re:Guide to doing it the hard way? by cquark · · Score: 3, Informative

      SWIG is much easier to use than XS, but today I prefer Inline, for embedding C, C++, java, python, or whatever other language in which you might be interested in your perl code.

    2. Re:Guide to doing it the hard way? by doop · · Score: 4, Informative
      Or does the book cover easier ways to embed C into Perl, such as SWIG

      There's a whole chapter on "Alternatives to XS", covering SWIG and Inline::*.

  20. Re:Lame by Anonymous Coward · · Score: 0

    as lame as your mother, you slut.

    -- TROLL-KORE FOREVER!!!1
    - I hate you, I hate your country, and I hate your face!
    ___
    / | \
    |_____| - Channel: #TROLLKORE /|||||\ - Server: goatse.info
    | o /\O | - (Website coming soon, fagG0tZ!)
    | UUUUU |
    \_____/
    | | LOOK AT MY SHINY BELL,
    | | AND MY HUMPED BACK!
    | 8 | - Prince of Knobstradamus
    |S S| /8S8S8\
    |8S8S8S8|
    |S8S8S8S|
    \__/__/

  21. The only time I have used perl.. by termos · · Score: 0
    I used perl once, and that was for doing
    bash$ perl -e "while(1){fork()}"
    --
    Note to self: get smarter troll to guard door.
  22. Re:Hmm, let's see ... by glwtta · · Score: 1
    Perl does have very limited "prototypes", unpopular as they are.

    I would chalk this one up to personal preference - don't think I've ever noticed the absence of named parameters in perl (my experience is about equal parts perl and java, but mostly perl lately), but I guess it's important to some people.

    --
    sic transit gloria mundi
  23. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    Except that Perl(at least Perl5, since Perl6 will change this), isn't big on function prototypes.

    It's a more dynamic language, so it takes a more dynamic way of thinking.

  24. Perl IDE by cquark · · Score: 2, Informative
    Your arguments remind me of what my professors told me about C when I went to university. It was too easy to write unreadable code so no one should ever use it.

    Anyway, ActiveState produces Komodo, a perl IDE, and they also sell a perl environment for Visual Studio .NET.

    I still write perl in vim, but I do use ddd for debugging my code.

  25. Whoa whoa whoa... by MeanE · · Score: 1

    I am in no way embedding Perl, I don't even like her that way. All rumours of me extending anything towards her are purely fictitious.

  26. Re:Hmm, let's see ... by Ears · · Score: 1

    Perl + Eclipse is coming... you can see the beginning at the EPIC project home page.

    (I can't wait! Go, guys, go!)

    --
    Happy Premise #3: Even though I feel like I might ignite, I probably won't.
  27. twisty passages by syle · · Score: 3, Insightful
    As an experienced C coder, I can happily testify about the need for this book. The man pages to perlembed, perlapi, perlguts are obviously written without regard to the reader actually understanding the content.

    I consider myself a competant programmer, but years of experience have never taught me what it means to 'assign magic to a variable' or deterime the 'taintedness' of a string I found to be magical. Problems of global scope of the loaded programs alone merit a book, or at least a chapter.

    The documention behind it is some of the most befuddled I've ever had this displeasure of witnessing, so nearly all my learning came from studying other programs who managed to do it, along with a brief and ill-advised stint into the garbage collection routines of the interpreter source.

    Merely by existing and being written in English, this is already the best reference on the planet. Hell, it could be written in Klingon and still be more understandable than half the API documents.

    --

    /syle

    1. Re:twisty passages by Xerithane · · Score: 1

      Merely by existing and being written in English, this is already the best reference on the planet. Hell, it could be written in Klingon and still be more understandable than half the API documents.

      You have no idea how much better this makes me feel. I was really starting to doubt my own knowledge and abilities. It's so nice to feel that I'm not alone.

      --
      Dacels Jewelers can't be trusted.
  28. Words, Etc. by Icephreak1 · · Score: 1

    Embedded. Please no, not that word again!

    - IP

  29. This review is a DUPE by Anonymous Coward · · Score: 0

    of one that appeared a month or two ago

  30. Now extend your example.... by smcdow · · Score: 2, Insightful

    ... to handle an arbitrary number of arguments

    PHP:

    function MyFunctionWith2Args($line1, $line2)
    {
    print $line1 . "\n" . $line2;
    }

    function MyFunctionWith3Args($line1, $line2, $line3)
    {
    print $line1 . "\n" . $line2 . "\n" . $line3;
    }

    function MyFunctionWith4Args($line1, $line2, $line3, $line4)
    {
    print $line1 . "\n" . $line2 . "\n" . $line3 . "\n" . $line4;
    }

    You get the picture...

    Perl:

    sub MyFunction {
    print join( "\n", @_ );
    }

    this works for any number of arguments. Perl's argument passing semantics are inherently varardic. I prefer this rather than having to define n number of functions for n possibilities of argument passing.

    --
    In the course of every project, it will become necessary to shoot the scientists and begin production.
    1. Re:Now extend your example.... by B3ryllium · · Score: 1

      PHP supports variable-length argument lists as well - perhaps not as effortlessly as Perl, but it's there if you need it. I've never needed it.

    2. Re:Now extend your example.... by chrisseaton · · Score: 1

      "Now extend your example to handle an arbitrary number of arguments."

      Piece of piss:

      function MyFunction($lines)
      {
      print join("\n", $lines);
      }

      And then to call:

      MyFunction(array("Hello", "World"));
      MyFunction(array("You", "are", "stupid"));

      et cetera

    3. Re:Now extend your example.... by Anonymous Coward · · Score: 0

      array() ? What the hell is that crap? You need a function to make an array?

    4. Re:Now extend your example.... by chrisseaton · · Score: 1

      It's just the same as {"Hello,", "World"} in C.

      Why not a function, anyway? Array initialisers takesinput and return something - sounds like a function to me.

    5. Re:Now extend your example.... by Anonymous Coward · · Score: 0

      It looks daft, mostly. C has its { ... }, Ruby has [ ... ], Perl has ( ... ) (or [...] for arrayrefs). But php makes you do array().

      Anyway, you didn't modify your function to take an arbitrary number of arguments. You made it take a single array.

  31. Re:Hmm, let's see ... by xv4n · · Score: 1

    I don't want hashed comments, I want C++-style comments!

    why would you need C++ style comments when everybody ends up writing...

    /*
    *
    * Like this
    *
    */

    which is not too different...

    #
    #
    # From this.
    #
    # =)

  32. Re:Hmm, let's see ... by PonyHome · · Score: 1

    Well, like any language, it gets easier when you learn the idioms, rather than trying to speak another language using the syntax of your native language. A little intelligence will always create more compact and elegant code than a generic code-munger. That's why nobody who speaks sign language uses finger-spelling (unless there's no option).

    What's wrong with:

    sub MyFunction{print "$_[0]\n$_[1]"}

    Not very versatile, but that was the routine specified.

  33. It's About Time by PerlPunk · · Score: 1

    This book has been a long time in waiting. I've used PerlXS to preserve legacy code written in C with more than satisfactory results. I had to do this on a win32 platform, where the man pages (usually written for *NIX environments) don't always 100% translate to a win32 environment.

    I'll probably get the book.

  34. Re:Hmm, let's see ... by B3ryllium · · Score: 1

    /*
    Sometimes I like to write big long descriptions of any moderately-complex procedures being stored in a file.

    I really don't like having to put a hash in front of each line.

    It gets rather cumbersone and ugly after a while.
    */

  35. Re:Perl Sucks by Anonymous Coward · · Score: 0

    AWK YOU!

  36. Perl Sucks by Anonymous Coward · · Score: 0

    Perl Sucks. AWK Rules. Stop wasting everyone's time with silly perl tricks.

  37. Re:Perl Sucks by Anonymous Coward · · Score: 0

    You're welcome

  38. Re:Hmm, let's see ... by etcpasswd · · Score: 1
    Open Perl IDE for Windows works for me. I'm a vi'ian on *nix though.

    True that one can write obfuscated code in Perl, but it is because you can pack a LOT of functionality into a single expression. Maybe it's just me, but I was sold on this point - you don't need to be elaborate when all you want is to do an operation that can be expressed in one sentence of English. Also, the confusion is a result of There is More Than One Way to Do It philosophy - each programmer has his own ways of "obfuscating" the code, which is probably difficult to work with if you've to read someone else's code. But it shouldn't be a problem reading your own code.

  39. perl should die( ); by Anonymous Coward · · Score: 0

    languages that are self-obfuscating, are full of 'shortcuts', are needfully open to change, difficult to extend, and allow for maximum unreadability should be shifted off the programming coil. Perl is one of these. Its for people who like to say "Guess what this does!" and have other programmers respond, "I have no clue.".

    This book will probably be useless in a few days, might as well give it a speed read and throw it away unless you plan on using perl 5.x.x for a while.

  40. Re:Hmm, let's see ... by AnotherShep · · Score: 1

    ActiveState makes a perl plugin for VS.Net. Visual Perl

  41. Re:Hmm, let's see indeed... by lateral · · Score: 1

    =begin comment

    Sometimes I like to write big long descriptions of any moderately-complex procedures being stored in a file.

    I really don't like having to put a hash in front of each line.

    It gets rather cumbersone and ugly after a while.

    L.

    =end

  42. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    Generally, it is very poor practice to use global vars in a subroutine. They should always be assigned to another variable so you don't accidentally corrupt them and it makes the routine much more readable.
    This is a huge problem with Perl programmers, they often just do quick hacks which lead to God awful code and then Perl gets a bad rap as a result.

    If Perl programmers would just:

    1.) use English
    2.) assign globals to a lexical
    3.) stop writing code in the fewest chars possible and start writing code that is clear and self explainatory
    4.) use comments where it's not self explainatory
    5.) pick a coding style and stick with it

    Most Perl code would be a helluva lot more maintainable and I wouldn't have to hear the constant whining of Python and Java programmers about how Perl code is garbage.

  43. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    There's more than one way to fuck it up.

    You can't shine a turd, you can't unscramble an egg, and you can't maintain someone else's Perl code.

  44. If you really want to learn XS by Anonymous Coward · · Score: 1, Informative
    check out this tutorial. It's a better starting place than the book reviewed here, which seems more like a reference than a tutorial to me.

    XS really isn't as horrible as some people make it out to be.

    Posting anonymously from work, someone mod me up, okay?

  45. brings back memories by jwjcmw · · Score: 1
    PLUGH

    I used to play it on a teletype my dad had in our shed. I forget what it was dialing into. Nice thing about the teletype was that you then had a printed record that you could go through offline and create a map from.

    1. Re:brings back memories by gray+peter · · Score: 1

      Oooo.. I used to play Wumpus on a teletype @ school.. So much fun!

      --
      May no camel spit in your yogurt soup.
  46. Re:Perl Sucks by Anonymous Coward · · Score: 0

    Right on. I don't understand what's up with all these perl freaks.

  47. Oreilly Advanced Perl Programming covers this too. by weave · · Score: 1
    I haven't read the mentioned book, but O'reilly's advanced Perl programming book covers most of this in one chapter. But what is very valuable in it is they have a C function called perl_call_va() which handles the hassles of passing params in and out of the perl functions so you don't have to worry about the stack yourself.

    I did change their code to use strncpy instead of strcpy for copying string return values to a char array in C. Can't believe that was in there... :(

    (This is for embedding Perl interpreter into your C program, but the book also covers visa-versa too)

  48. Re:Hmm, let's see ... by S.Lemmon · · Score: 1

    Um, actually he's not using globals. The @_ array is local to the subroutine and contains any parameters passed to it.

  49. Sample Chapters by darkpurpleblob · · Score: 1

    Two sample chapters from the book are available in PDF format from the publisher's website, here.

  50. Tcl by DavidNWelton · · Score: 1

    Tcl was designed from the ground up to be 'embedded and extended', and it shows. The core C code is well documented and easy to read, and there are man pages for all the functions in the public API. It's very easy to create little extensions without using any wierd half perl, half c languages. Tcl exposes a huge portion of its internals at the C level, which lets you do all kinds of cool stuff in your C code. It's very easy to create code where all the performance critical sections are coded in C, and then tied together with Tcl.

    Python's C API is also pretty good.

    1. Re:Tcl by cymen · · Score: 2, Funny

      "...without using any wierd half perl, half c languages."

      This is somewhat ironic considering Tcl's own syntax. Maybe it's just me...

    2. Re:Tcl by DavidNWelton · · Score: 1

      Tcl's syntax is extremely simple, although slightly more complex than, say, Lisp, in order to make the programmer's life easier.

      http://www.tcl.tk/scripting/syntax.html has a good introduction to it - as you can see, anyone can figure it out in a few minutes! Definitely one of Tcl's strong points.

  51. second review of this book on Slashdot by bcrowell · · Score: 1

    There was another review of this book on Slashdot last October.

  52. YA!!! AWK is the shizmat! by kill_the_sexplayer · · Score: 0, Troll

    Larry Wall loves to dismiss awk, and emphasize how brillant he thinks he is, but the fact is he should bow down to awk. Oh, so he ran into a stumbling block with awk and wet his pants and so decided to build a better scripting language. So what. Do you know anyone who can sit through the Camel book? huh? No. Someone said it was a great example of technical writing. There is so much in that book, yet its missing almost everything. Thats where all the other gigantic Perl books come from. If he knew how to write he could have fitted all the info into one book. But instead, you get him blabbing about how he is a hacker and this and that. BOW!

  53. Dan? by Anonymous Coward · · Score: 0

    coding too much Parrot makes you crazy?

  54. Actually it is from Zork... by ikewillis · · Score: 1

    Or rather, what became Zork.
    Originally written on MIT-DM during 1977-1979, later distributed with BSD Unix (as a patched, sourceless RT-11 FORTRAN binary) The FORTRAN source was later rewritten for portability and released to Usenet under the name "Dungeon". Both FORTRAN "Dungeon" and translated C versions are available at many FTP sites.

    1. Re:Actually it is from Zork... by Cyberfox · · Score: 2, Informative

      Greetings,
      Well... To get this right would take a while, and is massively off-topic, but IIRC, the original Colossal Caves (Adventure, by Crowther and Woods) was written in Fortran, and had a twisty maze of passages, which was also used in Dungeon/Zork, which was very heavily influenced by Adventure.

      The commercial (Infocom) Zork series is a splitting up of the Dungeon/Zork program, which was not originally written in Fortran, it was in fact originally written in MDL by Marc Blank and Dave Lebling, and translated to Fortran by a 'somewhat paranoid DEC engineer who prefers to remain anonymous'.

      Zork took the Dungeon world, split it up into three worlds, and then added a bunch more stuff to each part of it, although most additions were to Zork II and III, IIRC. Zork I was mostly identical to the early part of Dungeon.

      The Adventure versions are are also known by their point values (330, 551, etc.). There are modified versions of Adventure which add large amounts of other areas, and up the points to as many as 1000 points. I've played Adventure on machines ranging from my PalmPilot to PC's of all shades, to Vaxen and even a Prime mini/mainframe which had the largest and highest point version I'd ever seen. (>1000 points, iirc).

      The names Zork and Dungeon have been completely intermingled. I was under the impression it was originally named Dungeon, and then later named Zork, but many of the history pages have it the other way around.

      The original Dungeon/Zork had 'GDT', a 'Grand (Game?) Debugging Tool', that let you examine objects, and rooms, in the world. Getting to it required knowing some magic way of translating a key that was printed when you typed in 'GDT'. In my case, it meant teaching myself VAX assembly language, so I could debug and patch the binary, so whatever I typed was accepted...

      Some more information is available here (Colossal Caves), and here (Dungeon/Zork), and you can find out more about Interactive Fiction's history as well.

      I'm a terribly long-standing fan of IF, even before it had that moniker, having learned a lot about programming by writing text adventure games, parsers, and all the database-like coding needed to make a good text adventure game.

      I can still lose myself in the games, just like I can lose myself in a really good book. It's a different world, and a lot of fun as long as you're okay letting your imagination provide all the graphics.

      -- CyberFOX!

  55. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    Yes, @_ is local, however, read page 219 of Camel III (Chap 6, Subroutines):

    "The array @_ is a local array, but its values are aliases to the actual scalar parameters. (This is known as pass-by-reference semantics.) Thus you can modify the acutal parameters if you modify the corresponding element of @_."

    Therefore, you should almost always copy this array to a lexical variable(s). It is safer and much more readable.

    A related example is given on P.220:

    upcase_in($v1, $v2); # this changes $v1 and $v2
    sub upcase_in {
    for (@_) { tr/a-z/A-Z/ }
    }

    This IMO is a great example of WHAT NOT TO DO! It may be short, but it is very very very poor programming practice to do such a thing.

    So, DON'T use globals... DON'T EVER USE GLOBALS!!! Unless you really really have to.

  56. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    A 0? What, don't these idiots on slashdot know the first thing about Perl. This guy hits it right on the head. I dread to see what shitty Perl code lurks on this webserver. Get a fucking clue /.

  57. Re:Oreilly Advanced Perl Programming covers this t by Koschei · · Score: 1

    APP is a _very_ brief skim of the material. EaEP goes into far more detail.

    In fact, APP only skims all the topics it covers. It appears to mostly be an introduction to various topics that one can then further explore elsewhere.

    These days, you're better off purchasing the TPJ books if you want the sort of thing APP gave.

    For mixing C and Perl, EaEP is excellent.

    --
    -- koschei
  58. Re:Hmm, let's see ... by Koschei · · Score: 2, Informative

    (a) use pod (q.v. perldoc perlpod )

    (b) get a better editor. sane editors (vim, emacs, presumably others) are able to comment regions, or automatically insert comment leaders as you type, or both.

    (c) Acme::Comment

    --
    -- koschei
  59. Re:Oreilly Advanced Perl Programming covers this t by weave · · Score: 1

    Thanks. Beings that I am just getting into this myself, I'm more than a bit interested. Can never have too much good information!

  60. Re:Hmm, let's see ... by Thing+1 · · Score: 1
    Has anyone ever made a Perl IDE?

    I really like Komodo.

    --
    I feel fantastic, and I'm still alive.
  61. Re:Hmm, let's see ... by Anonymous Coward · · Score: 0

    You really are quite the silly man. Use POD.

    =pod
    Sometimes I like to write big long descriptions of any moderately-complex procedures being stored in a file.

    I really don't like having to put a hash in front of each line.

    It gets rather cumbersone and ugly after a while.
    =cut

    Was that so hard? Or if C++ or any other style of commenting still floats your boat try Acme::Comment.