in reply to Re^3: 5.40 released
in thread 5.40 released

I use map a fair bit in instances like this:

In that very limited scope, I feel it's fairly clear what $_ is. Another example: (And I'm sure there's a clever way to do that in one statement, and maybe someone smarter than me will suggest it.) Finally, this is also handy: That's about the largest scope that I use $_ for. After that, I tend to use $k (for key) when I'm iterating over a hash: I get that having $_ appear in code can be a little odd when the scope is anything larger than Quite Small -- it stops you from grokking the code and makes you go back and figure out what the heck the value is, and where it came from.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Replies are listed 'Best First'.
Re^5: 5.40 released
by hippo (Archbishop) on Jun 13, 2024 at 14:35 UTC
    $sth_insert->execute ( map { $fields{ $_ } } qw/ITEMNO OPTFIELD AUDTUSER AUDTORG VALUE TYPE LENGTH DECIMALS ALLOWNULL VALIDATE SWSET/ )

    This will work but using map just for a hash slice is overkill. You can instead do:

    $sth_insert->execute ( @fields{qw/ITEMNO OPTFIELD AUDTUSER AUDTORG VAL +UE TYPE LENGTH DECIMALS ALLOWNULL VALIDATE SWSET/} )

    🦛

      Thanks -- you're absolutely right. There's no one else to do code review, so that kind of cleanup gets missed.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.