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!
| [reply] [Watch: Dir/Any] [d/l] |
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. | [reply] [Watch: Dir/Any] [d/l] [select] |
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.
| [reply] [Watch: Dir/Any] [d/l] [select] |