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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The PBP rationale is (very loosely (and probably poorly :) paraphrasing; see p100-101) that the Perl-style iteration is more explicit in that you can see right off what's being iterated.

## Compare . . . for( my $i = 0; $i < $#array; $i++ ) { frobnitz( $array[ $i ] ); } ## VS for my $item ( @array ) { frobnitz( $item ); }

The first case the fact that it's working with each element of @array isn't as readily apparent (you've got to parse that it's looking at $#array and then match that up with the indexing); whereas the foreach-style comes right out up top and says "I'm frobnitz'ing every item of @array".

Another thing is that in order to use the C-style loops you need to have an actual array to work with, whereas a foreach-style loop will work with any arbitrary list of values (e.g. for my $key ( sort { $h{$b} <=> $h{$a} } keys %h ) { ... }).

Again it's just a style issue and it's not "wrong", per se; it just doesn't read as . . . "Perlish".

The cake is a lie.
The cake is a lie.
The cake is a lie.

In reply to Re^3: globbing filehandles in arrays by Fletch
in thread globbing filehandles in arrays by why_bird

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2021-12-07 19:33 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (34 votes). Check out past polls.