I’m trying to understand a particular Perl code from vcake. Usually I find my way around in Perl but the following statement baffles me. I suspect that this is simply an error but I’m not completely sure. The statement is:
foreach my $seq (keys %$set) { if( (defined $set->{$seq}) and (my $numReads >= ($coverage)) ) { do something; } ... }
$coverage has been defined at the beginning of the file as a scalar integer (e.g. 10) and is never again written to. $numReads is only used in the line above, nowhere else!
$set, on the other hand, is modified inside the loop so the first part of the condition makes perfect sense. What I don’t understand is the second part because as I see it, this will always evaluate to the same value and I don’t understand the significance of $numReads or >= here. Can someone please enlighten me? Are there perhaps invisible automatic variables involved?
my $numReadsmeans: Create a new local variable within the context of theforeachloop. Its initial value isundef, which in numerical context is treated as0. So the code reads:which means ‘do something’ is never executed unless $coverage is set to 0 or less.
If this was debug code, I’d assume that $coverage is used to enable/disable this statement.
My guess is: You’ve found a bug.