Hey all, I can't understand the behaviour of my code... Here is my code
$hash = { "s" => "", "d" => "19.28.18.28", "p1" => "", "p2" => "88" }; $s="192.168.3.79"; $d="19.28.18.28"; $p1="3269"; $p2="88"; print $s." -> ".$$hash{"s"}."\n"; if ( $s =~ $$hash{ "s" }) { print "\t1 ok\n";}else { print "\t1 NOK\n" +;} print $d." -> ".$$hash{"d"}."\n"; if ($d =~ $$hash{ "d" }){ print "\t2 ok\n";}else{ print "\t2 NOK\n";} print $p1." -> ".$$hash{"p1"}."\n"; if ($p1 =~ $$hash{ "p1"}){ print "\t3 ok\n";}else{ print "\t3 NOK\n";} print $p2." -> ".$$hash{"p2"}."\n"; if($p2 =~ $$hash{ "p2" }) { print "\t4 ok\n";}else { print "\t4 NOK\n" +;}

Output

192.168.3.79 -> 1 ok 19.28.18.28 -> 19.28.18.28 2 ok 3269 -> 3 NOK 88 -> 88 4 ok

And when I comment the second test (if ($d =~ $$hash{ "d" }){), it prints:

Output

192.168.3.79 -> 1 ok 19.28.18.28 -> 19.28.18.28 3269 -> 3 ok 88 -> 88 4 ok

Why the third test could be one time true and the other time false ?

Thanks

In reply to Multiple Test Regex Does not work the way I expect by stunbox

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.