Why does your Perl way involve cramming everything together, while your C way has whitespace around operators like =?

I dont tend to put a lot of whitespace in my subs. The "C way" wasnt written by me so I can't explain.

And why does your Perl way have strangeCaps?

Both have camelHumpIdentifiers. Its part of the original PM convention. Personally I hate it and would prefer perl_style_identifiers instead.

Iteration over @_ to just use its first element?

You didnt read the code very closely then, iteration over @_ occurs in both and is intended to convert all node_id's in the argument list into $NODE hashrefs. The fact that a return is generated from the first non $self argument is just an added utility. Imagine you might say:

my @ids=(1,2,3,4); getRef(@ids); printLog($_->{title}) for @ids;

Why are the curlies different?

I use cuddled else style curlies. Obviously the author of that nodes doesnt.

Im not really sure what your point here is. Sure my way isnt the only one, sure there are other ways that are still "the perl way". But clearly the first isnt one of them, or at least wouldnt normally be perceived as such.

Anyway, I think you totally missed the point. The point was that using proper Perl idiom you wouldnt go through all the extra work the original does to do what it is meant to do. And that for someone used to the idiom even realizing that the two code snippets are identical takes a bit of thinking. Or it did me anyway.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi



In reply to Re^2: The trouble with Perl Idiom by demerphq
in thread The trouble with Perl Idiom by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.