in reply to 'block' idiom needed

You've just asked for 'return', haven't you?

sub block { my $setting = 0; { return $setting = 1; } }

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: 'block' idiom needed
by nmerriweather (Friar) on Jan 07, 2007 at 00:29 UTC
    no, return will exit the sub. i just wanted to exit the braces.

      Well yes... but then you just said return $setting outside of the braces. It'd be better for locality to not escape the braces just to get to the return and instead just do the return directly.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        ah. sorry for the confusion.

        This is a VASTLY simplified section of code. in practice its more like:
        sub configure { my $setting_a= undef; my $setting_b= undef; { run a bunch of things setting combinations of a or b , last } do someting with settings a and b }
        there are too many sub vars needed in the block to have that stuff in a seperate sub without passing tons of args around -- so i wanted to localize them in a breakable block