Perl6 Bracket Match

#!/usr/bin/env perl6

my \stdin = $*IN;

my $count = ~stdin.get();

my %table = 93 => 91, 41 => 40;

my @list = (91, 40);

for ^$count {
    my $str = ~stdin.get();

    my @chars = $str.encode('ASCII')[0 .. * - 1];
    
    my @stack;

    for @chars -> $ch {
		if @stack ~~ 0 || ($ch (elem) @list) {
			@stack.push: $ch;
		} else {
			if @stack[* - 1] == %table{$ch} {
			@stack.pop();
			} else {
			say "No";
			exit;
			}
		}
    }
    say @stack ~~ 0 ?? "Yes" !! "No";
}

编程技巧