dudes--

what if one and only one of my arrays has any data, and it's a single element? e.g.

$self->{foo} = []; $self->{bar} = []; $self->{gotit} = [ 5 ];
the grep trick below will fail because $seen{5} will = 1. any ideas for dealing with this scenario with equal cleverness?

hi monks--

this might be a stupid way to do what i'm doing, but now i have to know. i have an object like this:

$self->{foo} = [ 1, 2, 3 ]; $self->{bar} = [ 4, 5, 3 ]; $self->{nerd} = [ 3, 4, 8 ]; $self->{geek} = 1; $self->{useless} = 1;

now i want to find the array elements in all of the above that are the same. but i don't know which accessors have arrays and which don't. they only will have arrays if i put something there interesting, but i have no idea which ones will be used at any given time. so i do this, assuming i do know all possible accessor names:

foreach(@accessors) { if( ref($self->{$_}) eq "ARRAY" ) { push @tocheck, $_; } }
How do I now compare the contents of all the arrays i want to check? kind of like what would do this magic:

foreach my $e ( all the self->{dontknow}->[]'s in @tocheck ) { $isect{$e}++ }

Is there something smarter I can do other than push @tocheck? Is this the time for me to finally understand map? I've only used eval for the first time in my life today...


In reply to how do i find common elements of X number of arrays whose names i don't know? by basscakes

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.