in reply to Another reason for perl beginners to read perldocs

I'd avoid statement labels ('LINE' in your sample) unless they are required. Especially in a small scope the target of loop commands is clear in any case and adding statement labels makes it look like more is going on than is actually the case.

Bare in mind that the Perl documentation has evolved over a long period of time and has contributions from many people with different personal coding idioms. Some (much?) of the sample code in the Perl docs does not reflect common Perl idiom, but is a pragmatic way of illustrating some specific language feature. You will often see use of old style bare word file handles for example, or C style for loops. That doesn't mean that those style elements are current best practice however!

True laziness is hard work
  • Comment on Re: Another reason for perl beginners to read perldocs

Replies are listed 'Best First'.
Re^2: Another reason for perl beginners to read perldocs
by Anonymous Monk on Jul 02, 2011 at 23:33 UTC
    A good rule of thumb is, if you have 2 or more loops, you might use a label. You need a label if you want to exit an outer loop from an inner loop :)

    Another good rule of thumb is, if you have 2 or more loops, start turning inner loops into function calls :)

      I would strengthen your first rule of thumb to: "You should only use a label if you have two or more nested loops and need to exit from an inner loop to an outer loop".

      I very much agree with your second rule except I would widen it to include any nested code: "If you have nested flow control blocks consider moving inner blocks into functions".

      True laziness is hard work
Re^2: Another reason for perl beginners to read perldocs
by Jim (Curate) on Jul 03, 2011 at 18:41 UTC
    I'd avoid statement labels ('LINE' in your sample) unless they are required. Especially in a small scope the target of loop commands is clear in any case and adding statement labels makes it look like more is going on than is actually the case.

    Here's Essential Practice number 4 of Damian Conway's Ten Essential Coding Practices:

    4. Label every loop that is exited explicitly, and every next, last, or redo.

    I adhere to this best practice except in the most trivial circumstances. Whenever there's a natural, logical label to use (e.g., LINE, RECORD, ROW, FROG), I use it. It makes my intentions explicit and clear.

    (See Perl Best Practices.)