in reply to Reference to a function

In general, when learning Perl, you can safely ignore any literature that spends a lot of time discussing C or C++ and comparing Perl to them. Perl is nothing like either of these languages. (This is a good thing.)


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

Replies are listed 'Best First'.
Re^2: Reference to a function
by flounder99 (Friar) on Jul 24, 2003 at 15:04 UTC
    I disagree. There are a lot of C programmers that are given the task of writing/maintaining perl scripts. Perl references are in some ways like C pointers but in other ways very different. Expaining the subtleties can be very valuable. They may be confusing to a programming newbie but they can sure help someone who is well versed in C. One of the best ways to learn something is to compare/contrast it with something you know well.

    --

    flounder

      There are a lot of C programmers that are given the task of writing/maintaining perl scripts.

      They should treat Perl as a completely new language, just as they would lisp, and read introductory materiel on it.

      Perl references are in some ways like C pointers but in other ways very different. Expaining the subtleties can be very valuable.

      This is true, and even the Camel book does explain the differences between pointers and references. However, the OP was talking about an article that described how a specific problem was solved in C and layed out a very specific solution using pointers. Trying to apply an article like that to Perl is not a useful approach. It's one thing to read how Perl scalars are different from C integers or strings, and something else again to copy a C implemention of an algoritm for parsing numbers out of strings and try to adapt it to Perl. The former is useful; the latter is like applying knowlege of bicycle riding when flying an aircraft.


      $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/