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" } } }
In reply to Re^3: Reg: Performance
by salva
in thread Reg: Performance
by sivaraman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |