Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^4: Changing every subroutine in many perl scripts

by GrandFather (Sage)
on Jul 25, 2012 at 22:24 UTC ( #983745=note: print w/replies, xml ) Need Help??

in reply to Re^3: Changing every subroutine in many perl scripts
in thread Changing every subroutine in many perl scripts

The loop would be better written:

for my $sub (@{$Document->find('PPI::Statement::Sub') || []}) { next if $sub->forward; for my $child ($sub->children) { if (ref $child eq "PPI::Structure::Block") { $child->start->add_content("my mars code"); } } }

The next if ... saves a level of indentation and is easier to understand (at least for me) than an unless.

Using a Perl style for loop in place of the C style for loop is easier to read, easier to understand, more compact and much less likely to get wrong.

True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983745]
[haukex]: You can put it in SOPW, but use <readmore> tags
[haukex]: Also you might want to label it "code review"
[haukex]: Unless you have specific questions, in which case SSCCE's are much better
[cbeckley]: Excellent, thank you.
[cbeckley]: CUFP is more appropriate for stuff that's finished^h^h^h^h more advanced state of completeness?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2017-03-24 15:08 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (304 votes). Check out past polls.