Thanks to the forum here I am now aware of how to create and assign variables within an if statement to matched variables. Now I'm trying to set the same variable $m1 with the below statements. Only one pattern will evaluate true at a time, so how do I assign $m1 to only the one that evaluates true without evaluating the other (that seems to clear $m1 if the last pattern evaluated is false)? Thank you as always, the script is coming along perfectly!

Update: In my effort to simplify, I did change one thing, which I believe makes things a bit more difficult; the 3rd matching statement is with a different string(output_2) to pattern match, so I rewrote it correctly below. That said, I believe what will make this work is to somehow only evaluate statements until one is shown to be true, then to breakout with $m1 set

if(my ($m1) = $output =~ /^(pattern1)$/ or my ($m1) = $output =~ /^(pa +ttern2)$/ or my ($m1) = $output_2 =~ /(pattern3)/) { $hash{$key} = $m1; }

In reply to Match a Variable to Only the True Statement by razmeth

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.