mantager has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/env perl use v5.14; my @array = (0, 1000..10_000, 'abcd'); for my $element (qw/a ab abc 100 1000 10000 abcd/) { say "With grep:"; if (grep {/^$element$/} @array) { say "Element $element is there"; } else { say "Element $element is not there"; } say "With given-when:"; given ($element) { when (\@array) { say "Element $element is there"; } default { say "Element $element is not there"; } } say ""; }
With grep: Element a is not there With given-when: Element a is there With grep: Element ab is not there With given-when: Element ab is there With grep: Element abc is not there With given-when: Element abc is there With grep: Element 100 is not there With given-when: Element 100 is not there With grep: Element 1000 is there With given-when: Element 1000 is there With grep: Element 10000 is there With given-when: Element 10000 is there With grep: Element abcd is there With given-when: Element abcd is there
|
|---|