in reply to Re^3: Open Filehandle once
in thread Open Filehandle once

"map in void context is no longer expensive. map is now context aware, and will not construct a list if called in void context."

Hi Ken, I wasn't referring to "throwing away the output" in terms of wasted resources, but rather in terms of unclear code.

map is a function that returns a list -- when it is used in void context it smells bad, because it forces the reader to double-check that the author didn't make a mistake, falling into the same general category as any other distracting syntax or idiom.

It's also a bad habit in general to use functions for their side effects, as those may change.


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^5: Open Filehandle once
by kcott (Archbishop) on Aug 26, 2017 at 15:57 UTC

    All good. As I said, I "agree" with not using it in that fashion. Sorry if I misinterpreted your reason, with which I said I "disagree".

    I would rarely use map in void context, nor have I often seen others code it that way, so "unclear code" has never really been much of an issue; however, I don't disagree that it could lead to confusing or distracting syntax.

    — Ken