in reply to Will a substitution in an if/else control structure default to $_?

A substitution will always default to whatever the current value of $_ is. I think your real question is "If I use something as the operand of a match operator, does that set $_ to it?" The answer to that is no.

What it looks like you're trying to do is take an lvalue to the result of $table->cell($rownum, 0..2). This is, generally, not something that's recommended to be done (though it is doable, kinda). Much better would be to have the $table object be asked to normalize the value that would be returned by $table->cell($rownum, 0..2) within the object itself. That way, you're probably using some sort of hash value. Even then, you can't do the whole $_ lvalue thing. Honestly, I don't like code that overuses $_. Just be explicit about what you're doing.

Now, instead of trying to reuse the operand, you could make the match and substitution a little smarter.

my $strip = '\x0'; $strip .= '\d+' if $table->cell($rownum, 0..2) =~ $strip; $table->strip( $strip, $rownum, 0..2 );
That requires coding up another method that would do something like
# The ... indicates "Whatever" - it's not meant to be syntatically-cor +rect Perl. sub strip { my $self = shift; my ($pattern, ... ) = @_; $self->{cells}[...] =~ s/$pattern//; }

See how that could work better?


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?