Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

if elsif else not working

by parksbanyon (Novice)
on Oct 10, 2013 at 02:51 UTC ( #1057662=perlquestion: print w/ replies, xml ) Need Help??
parksbanyon has asked for the wisdom of the Perl Monks concerning the following question:

if($TARX eq "exe") { &binary ;} elsif($TARX eq "ini" || "txt") { &text ;} else { &file_man ;}

The first two (exe and txt/ini) find the correct sub's but the else (ie any other file type) is not, its going to the text sub. I tried a multitude of options and rearrangememts prior to posting, but to no avail. I'm stumped.

Comment on if elsif else not working
Download Code
Re: if elsif else not working
by keszler (Priest) on Oct 10, 2013 at 02:54 UTC
     elsif($TARX eq "ini" || $TARX eq "txt") { &text ;}

      Thanks! It worked. I swear I tried that and it failed. Sometimes it's just best to step away for awhile.

Re: if elsif else not working
by Athanasius (Monsignor) on Oct 10, 2013 at 02:56 UTC
Re: if elsif else not working
by kcott (Abbot) on Oct 10, 2013 at 03:36 UTC

    G'day parksbanyon,

    Welcome to the monastery.

    "The first two (exe and txt/ini) find the correct sub's but the else (ie any other file type) is not, its going to the text sub. I tried a multitude of options and rearrangememts prior to posting, but to no avail. I'm stumped."

    The string "txt" is TRUE. A zero-length string is FALSE; all other strings are TRUE. [Update: Oops! '0' is also false.] See "perlsyn: Truth and Falsehood".

    The expression ($TARX eq "ini" || "txt") will always be TRUE, which is why the else block is never reached.

    I see two posts showing how to fix this.

    -- Ken

Re: if elsif else not working
by NetWallah (Abbot) on Oct 10, 2013 at 05:06 UTC
    Here is how it parses out:
    ~$ perl -MO=Deparse,-p -e 'if( $a eq "xx" || "yy"){1}' if ((($a eq 'xx') or 'yy')) { '???'; } -e syntax OK

                 My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057662]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-07-30 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (235 votes), past polls