"...We haven't learned "map" or "grep" yet..."
What does you discourage from reading the friendly manual and learning it by yourself?
Some sketch written in a hurry for your further inspiration:
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Data::Dump;
my @colors = qw(red green blue yellow pink purple brown);
my @drop = qw(pink brown);
my @expected = qw(red green blue yellow purple);
my $regex = join "|", @drop;
my @result = grep {!/$regex/} @colors;
is($regex, q(pink|brown), q(Regex seems to be OK!));
is(@result, @expected, qq(Heureka!));
done_testing();
dd \@drop;
dd $regex;
dd \@colors;
dd \@result;
__END__
It's not carefully tested. And may be there is a better solution. Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|