A Quiz about Operator Priorities

#!/usr/bin/perl

use 5.36.0;

# ------------------------------------------------

say 'Does priority say we print 2b or ! 2b?';

my($action_types) = qr/PAYMENT|SETTLEMENT|TRANSFER/o;

say "Action types: $action_types";

for my $action (qw/PAYMENT REFUND/)
{
say "Action: $action";
say "Case: 1. $action (1a): ", $action =~ $action_types ? 'Present' : 'Absent';
say "Case: 2. $action (2a): ", "$action (2b): " . $action =~ $action_types ? 'Present' : 'Absent';
say "Case: 3. $action (3a): ", "$action (3b): " . ($action =~ $action_types) ? 'Present' : 'Absent';
say "Case: 4. $action (4a): ", "$action (4b): " . ( ($action =~ $action_types) ? 'Present' : 'Absent');
say "Case: 5. $action (5a): " . ($action =~ /$action_types/ ? 'Present' : 'Absent');
say '';
}

Leave a comment

About Ron Savage

user-pic I try to write all code in Perl, but find I end up writing in bash, CSS, HTML, JS, and SQL, and doing database design, just to get anything done...