aquitaine1313 has asked for the wisdom of the Perl Monks concerning the following question:

As part of a perl script,I am attempting to have two lists compared with one another. Each element of both lists is composed of a literal value (a name) and numerical value. I wish to match literal values (ie the names), but as I attempt to do so, as it were, via iterators (I've tried to loop each list through for, foreach and while) and conditional statements, I find the interpreter matching each name on both lists, equivalent or not. To exemplify, I need to compare @a with @b. List @a and list @b, similarly, are composed of strings of this form: "name" "value"\n. the record seperator being a space. The script splits them correctly (they print out as list of names and values) but matches on every iteration when the lists are compared in a for or foreach statement,

Replies are listed 'Best First'.
Re: Pattern matching
by Hofmator (Curate) on Aug 14, 2001 at 15:19 UTC

    Please post some code which produces the results you describe. And put this code in <code> and </code>.

    -- Hofmator

Re: Pattern matching
by traveler (Parson) on Aug 14, 2001 at 18:37 UTC
    Posting code might help us to find the problem, BUT, why are you using lists? If you are checking to see if names from a are in b and if they are not identically ordered, wouldn't hashes be a better data structure? It sounds as though if you used hashes you could iterate over one, say, a's keys and see if they are in b.

    HTH, --traveler

      An example of the input and the desired output would be help also.
Re: Pattern matching
by Sifmole (Chaplain) on Aug 14, 2001 at 18:28 UTC
    Yes, please post some example code and we can probably help out more. Have you checked that you are using "eq" to compare the names and not "=="?