Was a valid statement in logic as it was always returning a value of 0. Now the outcome of the convo is simply the following:$fpcr = grep { /fpcr/ } @array ? 1 : 2;
from what I can gather, scalar is required in front of grep to make grep return a scalar value containing how many matches it made against the list @array. If you drop scalar, it will still be valid since grep returns a result in list form containing all the matches so it would evaluate to true if it returned anything in either fashion. Main question here is, why did adding parentheses around the grep statement make the logic valid, though having the brackets makes it easier to read, I would still assume that perl would interpret the code$fpcr = (scalar grep { /fpcr/ } @array) ? 1 : 2;
as a signle statement to test for truth for the ensuing ? 1 : 2 ... Obviously I'm wrong here so can some robed one enlighten me?grep { /fpcr/ } @array
In reply to Precedence of grep vs. ?: by blackjudas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |