Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Actually I find your comment diminishing towards all those fantastic computer linguistics that have been working so hard to incorporate iterative behaviors into the natural language of Perl.

Excuse me, syntactic sugar is in no way diminishing nor pejorative. It is sweet! I love it! It enables me to write things this or that way as I see fit for the task, conciseness, readability and so on, and it is one of the major strengths of perl.

I have demonstrated that the OPs foreach loop can be rewritten in terms of map and grep, and the internal code path is the same - the very definition of syntactic sugar. Nothing bad about that.

But my major point is: having a working solution means "job done" in the first iteration; improvement can be done into various directions (performance, readability, maintainability, conciseness, exploring grammar, to mention a few) and each has its place and merits.

Hash slicing is sweet - I use it all the time. But in the case of the OP, there's evaluating the sliced hash values at the moment the slice is done involved, so the examples you presented don't fit.

Furthermore, when programming, I am dumb or pretend to be so, because, as the saying goes

Debugging a program is more difficult than writing it in the first place. Therefore, if you write your program as smart as you are, you are, by definition, too dumb to debug it.

I have been clubbed to death by my cow-orkers for using the Highlander List Asserter for populating hashes

my %hash = ( foo => 'bar', (baz => $quux) x!! $quux, # list repitition, see "x" in perlop );

and they accused me of writing unreadable code and shunned me as a developer. They insisted in that particular piece to be written as

my %hash = ( foo => 'bar', ); if ($quux) { $hash{baz} = $quux; }

because nobody groks what x!! means. Silly, in my eyes, because once you see that construct, as strange as it may look, and reading the comment and reading perlop, you know what it does and won't forget it. Ah well...

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re^5: A more elegant way to filter a nested hash? by shmem
in thread A more elegant way to filter a nested hash? by jimpudar

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-23 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found