Oh, now I got it! The warning is not actually coming from the if ($2 =~ /^0$/) { line. Unfortunately, perl sometimes reports the line number where an if block starts when the warning actually occurs later in the block. That's what is happening here.
First, you perform a regex match against $name, setting $1 and $2. Then, you perform a regex match against $2. So far, so good. Then you print out the values of $1 and $2. Oops! That second regex match you just did has wiped out the values of $1 and $2!
jeffa's node shows two ways to solve this problem. Either assign the results of the first match to new variables:
my($first, $last) = $name =~ /(.+)&(.+)/;
Or replace the second match with a comparison:
if ($2 eq '0') {
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|