fork(1) download
  1. use warnings;
  2. use strict;
  3.  
  4. my @test_values = (
  5. [ '0', '1' ],
  6. [ '1', '1' ],
  7. [ '0', '0' ],
  8. [ 'A', 'A' ],
  9. [ 'A', 'B' ],
  10. [ '4349678L', '9' ],
  11. [ '4347946L', '9' ],
  12. [ '791517N', '9' ],
  13. );
  14. my $n = 0;
  15. for my $ar_ref (@test_values) {
  16. my @ch_val = @{$ar_ref};
  17. $n++;
  18. print $n. '.' . '#' x 20, "\n";
  19. for my $op ( '&', '&&', 'and', '=', '==' ) {
  20. test_op( $ch_val[0], $ch_val[1], $n, $op );
  21. }
  22. }
  23.  
  24. sub test_op {
  25. my ( $key, $value, $n, $op ) = @_;
  26. print "# [$key] $op [$value] ";
  27. my $rez = eval( '$key ' . $op . ' $value' );
  28. if ($rez) {
  29. print 'done';
  30. }
  31. else {
  32. print 'no';
  33. }
  34. print '[' . $rez . "]\n";
  35. }
  36.  
Success #stdin #stdout 0s 4728KB
stdin
Standard input is empty
stdout
1.####################
# [0] & [1] no[0]
# [0] && [1] no[0]
# [0] and [1] no[0]
# [0] = [1] done[1]
# [0] == [1] no[]
2.####################
# [1] & [1] done[1]
# [1] && [1] done[1]
# [1] and [1] done[1]
# [1] = [1] done[1]
# [1] == [1] done[1]
3.####################
# [0] & [0] no[0]
# [0] && [0] no[0]
# [0] and [0] no[0]
# [0] = [0] no[0]
# [0] == [0] done[1]
4.####################
# [A] & [A] done[A]
# [A] && [A] done[A]
# [A] and [A] done[A]
# [A] = [A] done[A]
# [A] == [A] done[1]
5.####################
# [A] & [B] done[@]
# [A] && [B] done[B]
# [A] and [B] done[B]
# [A] = [B] done[B]
# [A] == [B] done[1]
6.####################
# [4349678L] & [9] no[0]
# [4349678L] && [9] done[9]
# [4349678L] and [9] done[9]
# [4349678L] = [9] done[9]
# [4349678L] == [9] no[]
7.####################
# [4347946L] & [9] no[0]
# [4347946L] && [9] done[9]
# [4347946L] and [9] done[9]
# [4347946L] = [9] done[9]
# [4347946L] == [9] no[]
8.####################
# [791517N] & [9] done[1]
# [791517N] && [9] done[9]
# [791517N] and [9] done[9]
# [791517N] = [9] done[9]
# [791517N] == [9] no[]