The Regex test in your second presentation is not the same as in your original post.

In your original post you used the regex expression:

if(/;;HPLCColumn;;([0-9]+);/){ if ($number == 2){ $HPLC_Collum= $1; $number ++; }else { die ; }

Whereas in your response above you use:

if(<CONFIG>=~/;;HPLCColumn;;([0-9]+);/){ $HPLC_Collum= $1; }

Those are not at all the same. Hence, I don't think you're confirming what you think/say you're confirming by the latter example.

In the former (i.e., the original) case you only set $HPLC_Colum to result of the 1st capture group (i.e., $1) if the value of $number matches the number 2. In the latter case (i.e., in your response) you set the value of $HPLC_Colum unconditionally to the value of $1 from your regex.

So it looks to me like it is reasonable that you're getting the right answer from the latter but since I can see nowwhere in your original code where you set $number then either $HPLC_Colum never gets set or, presuming it is some global that gets set elsewhere in your code, then I can't tell if you ever get to set $HPLC_Colum.

Of course, in that original form, if $number doesn't match the number 2 then you would execute the die which I would presume would be obvious. So it looks like $number is set to 2 elsewhere but your regex is not matching so you don't get your match group set like you're expecting.

I concur with the other responders that you need to be using use strict; and use warnings; to make tracking down these kinds of problems easier. Also, as they suggested, getting familiar with and employing judicious diagnostic print statements to confirm that your variables are getting properly set is most helpful. I would also add that getting familiar with and judiciously using Perl's Debugger can also be helpful...and sometimes more convenient and straight-forward than messing with diagnostic print statements.

I get these types of challenges frequently and have developed a pretty standard diagnostic strategy to track down the sources of the problems (the strategy is usually a combination of judicuous use of diagnostic prints and the debugger).

ack Albuquerque, NM

In reply to Re^3: Cannot seem to pass number to a function by ack
in thread Cannot seem to pass number to a function by BlueInk

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.