Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to look for two different file extensions?

by Superbroom2.0 (Novice)
on Mar 09, 2017 at 17:47 UTC ( [id://1184067]=note: print w/replies, xml ) Need Help??


in reply to Re: How to look for two different file extensions?
in thread How to look for two different file extensions?

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!

Replies are listed 'Best First'.
Re^3: How to look for two different file extensions?
by haukex (Archbishop) on Mar 09, 2017 at 17:59 UTC
    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.
Re^3: How to look for two different file extensions?
by davies (Prior) on Mar 09, 2017 at 18:00 UTC

    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://1184067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-24 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found