#!/usr/bin/perl # vim: set ts=4 sw=4 et sta: use strict; use warnings; use Benchmark qw( cmpthese ); use Digest::MD5 qw( md5_base64 ); # https://www.perl-community.de/bat/poard/thread/16419 my @unfiltered = () x 100; # original sub map_grep1 { my @filtered = map { my $x = $_; chomp $x; $x =~ s/->\s*(.*)/$1/g; $x} grep { ! m/(^\s*([#].*)?)$/ } @unfiltered; return @filtered; } # linuxer sub map_grep2 { my @filtered = map { m/->\s*(.*)/ ? $1 : $_ } grep { ! m/^\s*(?:#|$)/ } @unfiltered; chomp @filtered; return @filtered; } # wer grep sub map_grep3a { my @filtered = map { s/^->\s*(.*)/$1/; $_ } grep { ! m/^\s*(?:#|$)/ } @unfiltered; chomp @filtered; return @filtered; } # wer grep+map sub map_grep3b { my @filtered = map { s/^->\s*(.*)/$1/ ; m/^\s*(?:#|$)/ ? () : $_ } @unfiltered; chomp @filtered; return @filtered; } # renee grep+map sub map_grep3c { my @filtered = map { s/^->\s*// ; m/^\s*(?:#|$)/ ? () : $_ } @unfiltered; chomp @filtered; return @filtered; } #print join $/, map_grep3b(), $/; #exit; my %check = ( 'original' => \&map_grep1, 'linuxer' => \&map_grep2, 'wer_map' => \&map_grep3a, 'wer_map+grep' => \&map_grep3b, 'renee_map+grep' => \&map_grep3c, ); # BENCHMARK cmpthese( -1, \%check ); # checks for correct data for my $k ( keys %check ) { # print to see if we test different sub routines printf "%15s : %15s %s \n", $k, $check{$k}, md5_base64( join $/, $check{$k}->()); } # While testing, these conditions gave different results for "original" and "linuxer" # - do a second comparison (second comparison shows different results) # - comparison after for loop (comparison gives different result to a run before the for-loop or without it) #cmpthese( -1, \%check ); __DATA__ # comment 1 .*regex 1 -> file path 1 # comment 2 .+regex 2 -> file path 2