in reply to How to work with Arrays of 83,000 values
Reformatted, your code looks like:
A few critiques, since as MidLifeXis points out, you don't tell us how it doesn't work.#!/usr/bin/perl use strict; use warnings; my @readingbooks = ("a b", "c d", "e f", "g h"); my @readingdate = (1991, 1992, 1993, 1994); my @catbooks = ("one", "two", "three", "client's", "five", "six", "sev +en", "eight", "a b"); my @catdate = (1980, 1981, 1982, 1994, 1984, 1985, 1986, 1987, 1991); my $rdbooks; my $rddate; my $cataloguebooks; my $cataloguedate; for (0..$#readingbooks){ $rdbooks = $readingbooks[$_]; $rddate = $readingdate[$_]; for (0..$#catbooks){ $cataloguebooks = $catbooks[$_]; $cataloguedate = $catdate[$_]; if (($rdbooks eq $cataloguebooks) && ($rddate == $cataloguedat +e)) { print "$rdbooks \t $cataloguebooks \n"; print "$rddate \t $cataloguedate \n"; print "wow \n\n"; } } }
it saves typing, reduces complexity, and makes intent more obvious.for my $i (0..$#readingbooks){ for my $j (0..$#catbooks){ if (($readingbooks[$i] eq $catbooks[$i])...
#!/usr/bin/perl use strict; use warnings; my @readingbooks = ("a b", "c d", "e f", "g h"); my @readingdate = (1991, 1992, 1993, 1994); my %readingbooks_hash; $readingbooks_hash{$_}++ for @readingbooks; my %readingdate_hash; $readingdate_hash{$_}++ for @readingdate; my @catbooks = ("one", "two", "three", "client's", "five", "six", "sev +en", "eight", "a b"); my @catdate = (1980, 1981, 1982, 1994, 1984, 1985, 1986, 1987, 1991); for my $i (0 .. $#catbooks) { if ($readingbooks_hash{$catbooks[$i]} and $readingdate_hash{$catda +te[$i]}) { print "$catbooks[$i]\t$catdate[$i]\n"; print "wow \n\n"; } }
There are a number of additional improvements, particularly swapping from coordinated arrays to arrays of hashrefs (perllol) or even formal objects (Moose), but this should dramatically improve your situation.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|