in reply to Braces around a section of code

As the others have already said, the blocks introduce a new scope, and there are quite a few things in Perl that are lexically scoped. Just to add some more to the list that haven't been mentioned yet: several pragmas, such as strict and warnings, are also lexically scoped, and there are a few (rare!) cases where one might want to temporarily disable parts of those pragmas for a very small block of code.

By the way, I would recommend properly indenting the inner blocks as well. perltidy can help.

Replies are listed 'Best First'.
Re^2: Braces around a section of code
by Tux (Canon) on Jun 30, 2019 at 12:23 UTC

    The inner block *might* have been indented properly by perltidy, but when it was done using tabs, it gets lost in the the cut-n-paste.

    I am not starting a discussin about leading whitespace here. I personally do not care at all, as long as it looks correct in my editor, you can mix tabs and spaces for my care. I more care about consistency and correct indentation (which seldom happens according to my own rules :P).


    Enjoy, Have FUN! H.Merijn

      Ah, good point, you are correct there is a mix of tabs and spaces in the original. But the innermost print appears to not be indented enough, so my comment still stands ;-)