I have a program that takes an array created in a loop and pushes it into an AoA. When I have all my arrays I look for a Intersection on them to find common elements in all Arrays. There can be almost infinite arrays.

How do I get my @comp data structure into the &intersection subroutine?

@comp can hold up to N arrays, so I'd like to pass the entire data structure in at once and output an array of all the Intersection elements into one CSV string.

I'm really confused on how to do it.
#!/usr/bin/perl -w use strict; my @array1 = qw{ bob larry melon fruit}; my @array2 = qw{ bob larry melon apple}; my array3 = qw{ bob larry fruit apple}; my @comp; push @comp, [@array1]; push @comp, [@array2]; push @comp, [@array3]; ############# # # I'm not sure what to do here to make the @comp AoA compatable with +the &intersection subroutine # ############ my $newIntersection = &intersection( \%array1, \%wisconsin, \%rockford + ); print join(" ", keys %{ $newIntersection }), "\n"; sub intersection { my ( $i, $sizei ) = ( 0, scalar keys %{ $_[0] }); my ( $j, $sizej ); for ( $j = 1; $j < @_; $j++ ) { $sizej = keys %{ $_[ $j ] }; ( $i, $sizei ) = ( $j, $sizej ) if $sizej < $sizei; } my @intersection = keys %{ splice @_, $i, 1 }; my $set; while ( $set = shift ) { @intersection = grep { exists $set->{ $_ } } @intersectio +n; } my %intersection; @intersection{ @intersection } = (); return \%intersection; }
What would be the reccomended process to get a data structure of Arrays into the sub?

In reply to How to change this AoA to be compatable with an Intersection Subroutine? by awohld

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.