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?

In reply to Re: Will a substitution in an if/else loop default to $_? by dragonchild
in thread Will a substitution in an if/else control structure default to $_? by Lawliet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.