in reply to Re^4: Removing partially duplicated lines from a file
in thread Removing partially duplicated lines from a file

Ah, thank you very much, defined sounds like exactly the type of thing I was looking for. I think I even skimmed over the perldoc for it before (I did learn about the existence of defined from a quick mention of it in "Learning Perl") but erroneously disregarded it in this case due to the perldoc bit that says "Use of defined on aggregates (hashes and arrays) is deprecated." Which is my fault for skimming rather than actually RTFM'ing, because the perldoc is pretty clear about what it actually meant by "use... on aggregates" via the examples it gives, and it doesn't mention anything being frowned upon for using defined in a scalar context on a single array element like the defined($columns[1]) you show.

Small follow up question. You chose to add parenthesis and switch the and to an && instead. I understand the different order of precedence between and vs. &&, but is there a reason you elected to rewrite it that way? Or is just a case of, "that's just the way I decided to write it"?

EDIT: Sorry, my brain saw added parenthesis where there were none.

I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious

Replies are listed 'Best First'.
Re^6: Removing partially duplicated lines from a file
by AnomalousMonk (Archbishop) on Jul 27, 2016 at 15:36 UTC
    You ... switch the and to an && ... is there a reason you elected to rewrite it that way?

    Personally, the use of  and or not and even  xor for enhanced readability in "simple" logical expressions is extremely seductive. However, these operators were not introduced to improve readability, but for flow control. Their ultimately low precedence is their raison d'être, and this low precedence introduces so many potental pitfalls when you try to use them for readablity enhancement that it's just not worth all the headaches. (And simple expressions have been known to become more hairy.) My practice is to use them for their intended purpose — although I have to admit I do find myself backsliding from time to time.


    Give a man a fish:  <%-{-{-{-<

      Thanks, I do use and or almost exclusively when I write code for no other reason than readability and the fact that my brain (fingers?) simply default that way when I'm actively typing code. You've given me food for thought to maybe rethink that and start training myself to default to && || instead.

      I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
      I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious