in reply to Re: Comparing hash keys and values with Regular Expressions
in thread Comparing hash keys and values with Regular Expressions

Hi there! I tested

if ($nonmatchhash{$nonmatchhashkeys} = $nonmatchhash{$nonmatchhash{values})

with both '=' and 'eq', and the output was the same both times: correct, which is exactly what I wanted it to be. But the thing is, my problem lies at the 'foreach', actually.. But thanks anyway and thanks for the correction of 'onnozel'. :)

Replies are listed 'Best First'.
Re^3: Comparing hash keys and values with Regular Expressions
by CountZero (Bishop) on Jun 30, 2012 at 18:21 UTC
    Yet, you are doing totally different things:
    • = assignment operator
    • == numeric test for equality
    • eq string test for equality

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re^3: Comparing hash keys and values with Regular Expressions
by ww (Archbishop) on Jun 30, 2012 at 19:52 UTC
    1. "with both '=' and 'eq', and the output was the same both times: correct" is NOT a comprehensive test of the truth or falsity of the advice you were given... which is itself correct, while your usage is NOT.
    2. You initially addressed your question to "wise ones." It would be consistent to carefully consider their answers, rather applying your logically-inadequate testing and then knocking out a answer that denies their wisdom.
Re^3: Comparing hash keys and values with Regular Expressions
by Anonymous Monk on Jun 30, 2012 at 19:24 UTC

    with both '=' and 'eq', and the output was the same both times: correct, which is exactly what I wanted it to be.

    That is what they all say

    my %foo; my %bar = ( 1, 2 ); if( $foo{1} = $bar{1} ){ warn "assignment is assignment"; } if( $foo{1} = 'any true value' ){ warn "assign any true value, expression is true"; } warn "foo eq bar ", int ( $foo{1} eq $bar{1} ); __END__ assignment is assignment at - line 5. assign any true value, expression is true at - line 9. foo eq bar 0 at - line 11.

    Just because the output is the same doesn't mean much, even a broken clock is right twice a day

    Think of it a different way, you have a problem you can't solve and you're asking for help in solving it --- maybe, just maybe, those you're asking for help know something you don't know

Re^3: Comparing hash keys and values with Regular Expressions
by ww (Archbishop) on Jun 30, 2012 at 20:07 UTC

    Update: Created on the basis of my own mistaken belief that the initial reply had hit the bit-bucket thanks to some error on my part. Ignore till reaped.

    You addressed your op to "wise ones".

    You have answers from amongst the wisest.

    It would be consistent if you were to heed the response (and now, responses) from those from whom you sought answers... rather than relying on a logically insufficient test of your mistake as a rebuttal.

Re^3: Comparing hash keys and values with Regular Expressions
by SayWhat?! (Novice) on Jun 30, 2012 at 20:31 UTC

    CountZero

    Ok, I admit I made a mistake when saying the output was the same.. Sorry 'bout that, but that's how we learn, right? After testing that piece of code again, with '=', I got the output I desired. But when tested with 'eq', I got the following message as well as an empty output:

    Useless use of String eq in void context

    I also got this error message for every single line of my code:

    Use of uninitialized value in String eq

    So what's that all about then? :s And how can I correct it by using 'eq' instead of '=' then?

      Double-check your quotes (of both flavors, if applicable).
      Double-check parens, braces, brackets.
      Post (cut and paste) code so other sets of eyes can actually see possible causes.

      And re your breezy "Sorry 'bout that, but that's how we learn, right?:
      while learning from one's errors is a valuable approach, so too is reading the docs when some "wise one" tells you the case or usage is something different than you thought. [ Been there, took a while to learn to do that :-( ]

      ... So what's that all about then ...

      Its easier to point out if you post the new code

      use diagnostics; for more verbose messages