On Thursday 29 Apr 2010 14:39:11 Akhthar Parvez K wrote: > There was a typo in my original email. I missed the word "not" which was > very crucial as always. > > Scenario: #1 > unless ( (defined $result) && ($test !~ /TEST/) ) > { my $result = "OK"; > print "$result\n"; > }
This unless with a negative test inside confuses me. Other people have replied so I'll just share a joke from Freenode's #perl: [quote] <polak> mauke: so how does that "translate" into eng <merlyn> "eng"? <mauke> I spe eng goo <rindolf> mauke: I spe eng wel <rindolf> I spe goo eng <sts> just a short question. besides personal preference is there any difference if you use if(! or unless(? <rindolf> sts: no. <rindolf> sts: they do the same thing. <Botje> sts: pfft. Real Men(tm) use unless(!...) <rindolf> Botje: heh. <sts> lol unless(! makes sense. thanks Botje, i'll rather use this one. =D <LeoNerd> For me it's a readability thing - I express what seems more likely <rindolf> Botje: File::HomeDir used to have a triple or quadruple negative in one of its test files. <Botje> unless(! $str !~ /(?!foo)/) <rindolf> Botje: heh <merlyn> whoa <merlyn> unless (!) makes no sense to me at all <Botje> of course not. <sts> Botje: wow! <Botje> it's still cool to confuse people with :] <LeoNerd> Heh.. Should just use !!! in there anywa y:) <merlyn> it's 7 characters too many <xand> some people don't understand double negatives <merlyn> I don't want no complaints! <Botje> xand: you mean don't not understnad? <LeoNerd> We don't know nobody who don't want no double-negatives <sts> Botje: what does (?!foo) do? <nanonyme> lol <xand> Botje: don't not misunderstand <mauke> Botje: that always executes the block <merlyn> there's an argument that can be successfully made that "I don't want no complaints" doesn't necessarily work logically <Botje> xand: oh, I don't not think I didn't not misunderstand you. <Botje> mauke: I know. it just looks cool. <mauke> and you want !($str !~ /.../) <xand> don't you?# <merlyn> so it might actually mean what people think they're meaning -- N-uple negative on Freenode's #perl -- #perl, Freenode [/quote] (From: http://www.shlomifish.org/humour/fortunes/sharp-perl.html#n-uple-negative ) I should note that I never use unless in my code because from some reason it mentally confuses me and I always have to transform it into if (!) in my head. Maybe it's a language thing (Mixed Hebrew/English cognition, in my case). As opposed to Uri I am using !~ (inside an if or an if clause) and read it as "does not match" and it's OK. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Parody on "The Fountainhead" - http://shlom.in/towtf God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/