grep is grepping everything. I've never had this problem with grep before.
You are using:
grep( lc $word, @short_sizes )
grep passes through any value where the expression (first argument) is true.
Your grep expression is lc $word. If $word has any value except undef, '' or 0, then lc $word will also have a value, and therefore be true, and everything in @short_sizes will pass through.
Since if( grep( ...,... ) ) { places grep in a scalar context, the result will be the number of items passed through, which will be the same as the number of elements in @short_sizes. So, unless it is empty, the if condition will be true.
Effectively, if (grep(lc $word,@short_sizes)) {
is the same as:if( defined( $word ) && @short_sizes > 0 ) {
which almost certainly isn't what you intend.
So, what are you trying to achieve with that construct?
If you are trying to check if any of the values in @short_sizes matches the lower cased value of $word, the you would need: if( grep( $_ eq lc $word, @short_sizes ) ) {
But that's just my guess as to your intent.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
|