in reply to Re: Re: Passing / evaluating / dieing on one line...
in thread Passing / evaluating / dieing on one line...
Your example is spurious, because it's bad code.
Now, adding a new column is a matter of changing the %Columns hash. In addition, it's much easier to factor out the %Columns hash to some configuration file this way than doing it your way.my %Columns = ( 'label' => 0, 'key' => 1, 'cross' => 2, ); foreach my $col_name (keys %Columns) { $Columns[$col_name} = column_exists( \@data, $_[1] || $Columns{$co +l_name} ); die if $Columns{$col_name} == -1; }
In addition, this lends itself to even further improvements. For example, consider
my %Columns = ( 'label' => { default => 0, exists => 0, }, 'key' => { default => 1, exists => 0, }, 'cross' => { default => 2, exists => 0, }, ); foreach my $col_name (keys %Columns) { $Columns[$col_name}{exists} = column_exists( \@data, $_[1] || $Columns{$col_name}{default} ) +; die if $Columns{$col_name}{exists} == -1; }
THAT is self-documenting code!
Furthermore, any time I see
I was to do something like:do_A; do_B; do_C; do_D; do_A; do_B; do_C; do_E; do_A; do_B; do_C; do_C;
It's cleaner, more maintainable, and more extensible.for (\&do_D, \&do_E, \&do_C) { do_A; do_B; do_C; $_->(); }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
In Section
Seekers of Perl Wisdom