Balaton: Athanasius has replied:
... I think it’s highly unlikely that this line:
if ($line =~ ModuleMatching::MatchLAC($locus_acc_no)) {
can be correct. But without knowing what sub ModuleMatching::MatchLAC is supposed to do, it’s hard to give advice.
I agree that the definition of ModuleMatching::MatchLAC() given in the OP is most likely some sort of dummy placeholder, but in any event, the given function can be explained as follows (this is for Balaton; I believe Athanasius understands all this quite clearly):
-
The function returns the result of a match of the passed argument $_[0] against a literal regex (i.e., a regex having no interpolations (Update: literal regex: my terminology may be a bit off here));
-
The function is called in scalar context imposed by the =~ operator, so the result of the match within the function is either 1 (successful match) or '' (the empty string; match failed);
-
The '' or 1 returned by the function is then converted to a regex (with 1 stringized to '1') and a match is made against $line. If the match is against /1/ the result is obvious.
If the match is against // (the empty regex, created from the empty string), the result will come from a match against the regex most recently matched or, if no regex has ever been matched, against the null regex, which matches anything. Straight from the docs: "If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead. [...] If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match)."
The problematic results of these matches can be illustrated as follows:
>perl -wMstrict -le
"for my $line ('', 'X', 'Y') {
for my $locus_acc_no ('', 'X', 'Y') {
if ($line =~ MatchLAC($locus_acc_no)) {
print qq{ match: '$line' =~ MatchLAC('$locus_acc_no')};
}
else {
print qq{NO match: '$line' =~ MatchLAC('$locus_acc_no')};
}
}
}
;;
sub MatchLAC { return $_[0] =~ /^X$/; }
"
match: '' =~ MatchLAC('')
NO match: '' =~ MatchLAC('X')
match: '' =~ MatchLAC('Y')
match: 'X' =~ MatchLAC('')
NO match: 'X' =~ MatchLAC('X')
match: 'X' =~ MatchLAC('Y')
match: 'Y' =~ MatchLAC('')
NO match: 'Y' =~ MatchLAC('X')
match: 'Y' =~ MatchLAC('Y')
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.