Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
map and grep are not picked up as quickly by new Perl programmers as for, for several reasons.

First, new programmers will have difficulty lining up multiple actions all at once. Compare these:

my @newlist = map { $_*2 } @list; my @list; my @newlist; for my $item( @list) { push @newlist, $item * 2; }
The first example examines all values of @list (one at a time of course), multiplies each value by 2, and saves all resulting values into @newlist.

The second example is easier for a newbie to manage. It loops through @list, one at a time. Each time through, $item will hold the active value. Multiply each value by 2, and save it in @newlist.

Second, it's easier to debug the 2nd example. There are several places to breakpoint or print out intermediate results to check that the code behaves as expected. Printing out intermediate results in a map is also easy, but it has to be done carefully to avoid munging the map return values.

My point is that a newbies coming from some other languages (those without map or grep) would be more comfortable with the 2nd form. Once entrenched, they are less likely to embrace map and grep without extra incentives.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: question for perl book & magazine authors by QM
in thread question for perl book & magazine authors by jfroebe

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 lurking in the Monastery: (3)
As of 2024-04-24 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found