in reply to Re^14: the annoying keys "key" and "value"
in thread the annoying keys "key" and "value"

It's not a question of efficiency, it's a question of actually working. $order=[somekey1,somekey2,...]; and {somekey1=>somevalue1,...} doesn't support more than one value with the same key.

Replies are listed 'Best First'.
Re^16: the annoying keys "key" and "value"
by jabowery (Beadle) on Dec 25, 2010 at 21:35 UTC
    For clarity, what you are calling an ordered associative array is actually an ordered relation. The definition of "associative array" is functional (ie: one value per key), not relational (ie: potentially N values per key). So we have:
    <ordered_relation_foo> <b>2</b> <b>4</b> <a>1</a> <b>6</b> <a>3</a> <a>5</a> </ordered_relation_foo>
    becomes:
    $ordered_relation_foo={ _meta_order=>[b,b,a,b,a,a], b=>[2,4,6], a=>[1,3,5]};
    So now a query of this ordered relation becomes:
    $ordered_relation_foo{a}
    How does that compare to the query of your structure?

      what you are calling an ordered associative array is actually an ordered relation.

      Perhaps. The choice of name doesn't change the point, though.

      How does that compare to the query of your structure?

      It contains the same information, and it does appear to be faster for some operations (comparable for the rest).

      > The definition of "associative array" is functional (ie: one value per key), not relational (ie: potentially N values per key).

      Whose definition? Not wikipedias!

      Language implementations differ, and users of different languages have problems to find reliable common terminology.

      Many monks already showed you that XML and HTML generally allow repeated tags with different entries.

      If you don't like this, please find an XML forum to complain, it has nothing to do with Perl!

      Or give me a reply to Re^3: the annoying keys "key" and "value" (XML-RPC) showing that multi valued or ordered keys are excluded by RPC's scheme definition.

      Cheers Rolf

        Wikipedia's definition supports mine. In fact it says explicitly: "Associative arrays are very closely related to the mathematical concept of a function with a finite domain." You undoubtedly think that when it parenthetically refers to "sets" in: "each key is associated with one value (or set of values)" that it is therefore allowing general relations as opposed to restricting to functional relations. Its not. Set theory reifies the "set" as a value.

        Appealing to the group is no argument at all. I don't care how many "monks" say something -- especially when it isn't even wrong (to quote W. Pauli). For instance, I never took issue with the desirability of expressing relations. I just don't like it when people go about doing stupid implementations of lookups. When people try to justify it by saying relations are valuable, it just multiplies the stupidity with irrelevance. When I show how to do a better implementation of relations just to play along and am further insulted, it progresses from stupid to comical.

      I went ahead and implemented an HTML parser to produce a "DOM" in accordance with the aforementioned structure.

      Here is the program to produce HTML from that "DOM":

      sub htmlize{ my ($tag_name,$dom)=@_; return $dom unless ref $dom; my $html; my %cnt; my $no_text; $html .="<$tag_name"; # print "<$tag_name"; for my $rank (0..$dom->{'_meta_attr_n'}-1){ my $attr_name=$dom->{'_meta_order'}->[$rank]; if($attr_name eq '/'){ $no_text=1; next; } my $attr=$dom->{$attr_name}->[$cnt{$attr_name}||'0']; $attr = join ', ',@$attr if ref $attr; $html .= " $attr_name=\"$attr\""; # print " $attr_name=\"$attr\""; $cnt{$attr_name}++; # in the unlikely event that a child tag a +nd this attr have the same name } $html .= '/' if $no_text; # print '/' if $no_text; $html .= '>'; # print '>'; for my $rank ($dom->{'_meta_attr_n'}..$#{$dom->{'_meta_order'}}){ my $tag_name=$dom->{'_meta_order'}->[$rank]; $html .= htmlize($tag_name,$dom->{$tag_name}->[$cnt{$tag_name} +||'0']); $cnt{$tag_name}++; } $html.="</$tag_name>" if !$no_text; # print "</$tag_name>" if !$no_text; return $html; }

      Is this unwieldy compared to the [{'key'=>$key_name, 'value'=>$value},...] structure?