Howdy Bros. I have some text titles in a database field, some of which have leading/trailing blanks and/or quotes that I want to get rid of. But I only want to update the record if the title was in fact changed.

I have this code for a simplified illustration of the problem

my @items = ('"Title Text Example"', 'Title Text Example', ' Title Tex +t Example ',' "Title Text Example"'); foreach my $title (@items) { $title =~ s/^\s*\"?|\"?\s*$//g; print length($&)," $title\n"; }
Question is, how do I tell if the substitution matched anything? I thought I could check $&, but it's zero length every time through the loop. I don't understand why that is, because it's supposed to give the last successful pattern match, and there are successful matches in every case except the second.

Steve


In reply to Determing if this regex matched by cormanaz

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.