If you're working with strings, then work with strings. A string uses less memory than an array of characters, and string operations are fast:
Even if you're working with arrays of characters, joining into strings will probably be faster:my $line1 = 'CABGFE'; my $line2 = 'DBF'; say for $line1 =~ /[$line2]/g;
my @line1 = qw(C A B G F E); my @line2 = qw(D B F); my $line1 = join '', @line1; my $line2 = join '', @line2; say for $line1 =~ /[$line2]/g;
If you've only simplified your example to arrays of characters, but they're really arrays of something else, then use a hash, as others have already suggested.
In reply to Re: Iterating through Two Arrays. Is there a better use of memory?
by Anonymous Monk
in thread Iterating through Two Arrays. Is there a better use of memory?
by Jeri
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |