For example, could I write something like:
my $var = "A" || "B";
where ($var eq "A") and ($var eq "B") would both evaluate to true? If not, is there some way around this?
Are you looking for Quantum::Superpositions?
Update: An example.
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Quantum::Superpositions;
my $var = any('A', 'B', 'C');
for ('A', 'B') {
if ($var eq $_) {
say "\$var equals $_";
} else {
say "\$var doesn't equal $_";
}
}
Output:
$var equals A
$var equals B
$var doesn't equal C
my $var = { A => 1, B => 1} and if ( $var->{$_} )EDIT:
From what I've gathered from your comments and previous question you have a string with chars and just want to check if one char is inside of it. Instead of constructing something like $var = "A" || "B" (which doesn't work) you can simply check if the needed char is in the string (with a simple regex):
$var = "AB";
if ($var =~ /A/) { # True
# Calculations
}
if ($var =~ /B/) { # Also true
# Other calculations
}
You cannot. It sounds like you misunderstand logical operator and bitwise operator.
| is bitwise operator, it works on bits.
|| is logical operator
From what you say, I presume you need logical operator, but be more specific.
You can get some help there: http://www.perlmonks.org/?node_id=301355
print $varoutput in such case?if ($var eq "A")should translate toif ($var{A})