Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to look for two different file extensions?

by stevieb (Canon)
on Mar 09, 2017 at 17:26 UTC ( [id://1184064]=note: print w/replies, xml ) Need Help??


in reply to How to look for two different file extensions?

if ($FileExt eq ".xlsx") || if ($FileExt eq ".pdf")

That doesn't do what you're attempting to do. Combine the conditional within the same if() statement:

if ($FileExt eq '.xlsx' || $FileExt eq '.pdf'){ ... }

Replies are listed 'Best First'.
Re^2: How to look for two different file extensions?
by Superbroom2.0 (Novice) on Mar 09, 2017 at 17:47 UTC

    I think I tried that but without the variable:

     if ($FileExt eq '.xlsx' || '.pdf'){

    I guess my thought is that it would say "If the variable for the file extension is this OR this, do this" Thank you for clarifying for me!

      if ($FileExt eq '.xlsx' || '.pdf'){

      Unfortunately that doesn't work, although TIMTOWTDI (There's More Than One Way To Do It):

      if ( $FileExt eq '.xlsx' || $FileExt eq '.pdf' ) { print "Match!\n" } if ( $FileExt =~ /^\.(?:xlsx|pdf)$/ ) { print "Match!\n" } use Quantum::Superpositions; # OR #use Perl6::Junction qw/ all any none one /; if ( $FileExt eq any('.xlsx','.pdf') ) { print "Match!\n" }

      Perl 6 supports Junctions natively, but note that Perl 6 is a related but different language that I wouldn't call production ready yet.

      Update: Added a word.

      A reply falls below the community's threshold of quality. You may see it by logging in.

      A little more - I hope - clarification. The code you have given translates roughly thus: "If the variable evaluates to '.xlsx' or if '.pdf' evaluates to true". IIRC, COBOL - at least some dialects - would do what you mean in this context, but Perl is more powerful and it's quite common for programmers to put in a variable (or even a constant like DEBUG) into a conditional, which is why the compiler doesn't treat your code as you meant it. I remember running into this while taking courses in Pascal and COBOL concurrently - nearly 40 years ago.

      Regards,

      John Davies

      Update: memories came flooding back overnight, including the fact that I have the COBOL for Univac 1100 manual, which says:

      In a compound conditional expression ... the subject may be implied. For example, AGE IS GREATER THAN 21 OR LESS THAN 65 ... Operators, as well as subjects, may be implied ... for example, DISTRICT IS EQUAL TO 25 OR EQUAL TO 66 OR EQUAL TO 85 may be written as, DISTRICT IS EQUAL TO 25 OR 66 OR 85

      The fun came when someone (not I) wrote X NOT EQUAL TO Y OR Z and it took lots of expansion and De Morgan's laws to explain that he needed to replace OR with AND.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1184064]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found