I only suggested an other approach... in case the person doesn't have much memory but has enough time to run it...

The orignal arrays (accoring to Devel::Size::total_size) uses 152 bytes, the @which-array (posted by ysth), uses 629 bytes. Your hash of array references uses 2200 bytes.

Using the same code but whit your example arrays: 2_000_072 bytes (for the first two and 2_000_052 for the last one), @which-array: 11_397_188, hash of array references: 44_886_169 bytes, which is 3,9 times more then the array. And that is in my opinion a lot more.

Used code:

#!/usr/bin/perl -l use strict; use warnings; use Devel::Size qw/total_size/; #my @array1 = (1,2,3,4,5); #my @array2 = (6,7,8,9,10); #my @array3 = (11,12,13,14,15); my @array1 = (1 .. 100001); my @array2 = (100001 .. 200001); my @array3 = (200001 .. 300000); print total_size(\@array1); print total_size(\@array2); print total_size(\@array3); print "-" x 10; my @which; $which[$_] = "array1" for @array1; $which[$_] = "array2" for @array2; $which[$_] = "array3" for @array3; print total_size(\@which); print "-" x 10; my %which; do { push @{ $which{$_} } => "array1" } for @array1; do { push @{ $which{$_} } => "array2" } for @array2; do { push @{ $which{$_} } => "array3" } for @array3; print total_size(\%which);


In reply to Re^5: matching values in arrays by Animator
in thread matching values in arrays by Anonymous Monk

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.