September 2015 Archives

How each drove me crazy

I had a program like this:

my @data = qw( bla fasel foo org jawohl hmblamm glfoo sdfoo sadfasffoo) ;

my %regex = ( type1 => bla, type2 => foo);

foreach(@data) {
print $_,"\t";
print " matches " if test_it($_);
print "\n";
}

sub test_it {
my $entry = shift;
while( my($type, $regex) = each %regex) {
return 1 if $entry =~ /$regex/;
}
return 0;
}

I expected:
bla matches
fasel
/users/vkroll/2015/09/index.html

About vkroll

user-pic I blog about Perl and "modern software development", english is not my mother tongue (I am german), so I hope you get, what I mean :-)