in reply to Re: modifying a file with regex!
in thread modifying a file with regex!

This extraneous "do" is completely unnecessary. It actually "harms" by introducing an unnecessary level of indentation - which is a hindrance to readability.

Replies are listed 'Best First'.
Re^3: modifying a file with regex!
by tobyink (Canon) on Mar 16, 2012 at 23:44 UTC

    It eliminates two calls to close and allows some lexical variables ($input_h and $output_h) to live in a smaller scope.

    Indent it however you like; this ain't Python.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Calls to close() are not necessary in any event (for this particular code). Code runs the same with or without the "do". The only argument in favor of this "do" is scope of $input_h, etc. The price of the extra indentation level is too high and the gain too low - because of the very limited "life" of these variables.

      I guess like all things, mileage may vary. In Perl, you can eliminate the "do" and just put {}, however I don't think either of these wise in this situation. Obviously you disagree.

        The price of the extra indentation level is too high and the gain too low - this ain't JAVA!

        LOL