in reply to Re^2: Reg: Performance
in thread Reg: Performance
When there are no entries for $readID in DUMP_B, $b{$readID} becomes undef, appending || [] handles this special case replacing undef by a reference to an empty array so that we can dereference it later as @$ac.$b{$readID} || []
A simpler version of the code follows:
BTW, when programming in Perl it is very unusual to use C-like (or Java-like) for loops. Instead, for (@array) { ... } and for (0..$top) { ... } are used.my %b; open(B, "<" . DUMP_B) || die("Could not open file \n"); while (<B>) { chomp; my ($id, $ac) = split /\|/, $_; push @{$b{$id}}, $ac; } open( OUTPUT, '>', 'INACTIVE_LIST' ) || die "Could not write to file\n +"; open(A, "<" . DUMP_A) || die("Could not open file \n"); while(<A>) { chomp; s/\s+//g; if ($b{$_}) { for my $ac (@{$b{$_}}) { print OUTPUT "$_|$ac\n" } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Reg: Performance
by sivaraman (Initiate) on Oct 29, 2010 at 12:57 UTC |