is($actual, $expected, $descriptionOfWhatYouTried); # to check effect of parameters passed to subroutine is(substr('abcdef', 0, 2), 'ab', q(tried subtr(..,0,2)}); # to check what got captured by a regular expression is(eval { 'abcdef' =~ /^(\w+)/; $1 }, 'ab', q{tried /^\w+/}); #### not ok 1 - tried /^\w+/ # Failed test 'tried /^\w+/' # in Monks/Snippet.pm at line 6. # got: 'abcdef' # expected: 'ab' 1..1 # Looks like you failed 1 test of 1. #### #changed is to isnt #This doesn't work. Captures 'abcdef' instead of just 'ab' isnt(eval { 'abcdef' =~ /^(\w+)/; $1 }, 'ab', q{tried /^\w+/}); #### #using perl MyExperiments.pl ok 1 - using /(..)/ ok 2 - using /(.)\1/ ok 3 - using /((.)\1)/;$2 ok 4 - using /((.)\1)/;$1 ok 5 - using /(.)(\1+)/;"$1$2" ok 6 - using /(..)/ ok 7 - using /(.)\1/ ok 8 - using /((.)\1)/;$2 ok 9 - using /((.)\1)/;$1 ok 10 - using /(.)(\1+)/;"$1$2" #using prove MyExperiments.pl MyExperiments.pl....ok All tests successful. Files=1, Tests=10, 0 wallclock secs ( 0.05 cusr + 0.04 csys = 0.09 CPU) #### use strict; use warnings; use Test::More qw(no_plan); #number of tests is constantly changing #changed is to isnt: #this doesn't work, results in 'ab' isnt(eval {'abcdeee' =~ /(..)/;$1}, 'eee', q{using /(..)/}); #changed is to isnt: #this printed out only 'e' isnt(eval {'abcdeee' =~ /(.)\1/;$1}, 'eee', q{using /(.)\1/}); #changed is to isnt: #this printed out undef isnt(eval {'abcdeee' =~ /((.)\1)/;$2}, 'eee', q{using /((.)\1)/;$2}); #changed is to isnt: #this also printed out undef isnt(eval {'abcdeee' =~ /((.)\1)/;$1}, 'eee', q{using /((.)\1)/;$1}); #BINGO! this worked is(eval {'abcdeee' =~ /(.)(\1+)/;"$1$2"}, 'eee', q{using /(.)(\1+)/;"$1$2"}); #### use strict; use warnings; #we have no plan! #usually want to pick and choose tests anyway #so the number is not fixed use Test::More qw(no_plan); #============================================================ # VARIOUS EXPERIEMENTS #============================================================ #--------------------------------------------------- #GOAL: find run of repeating letters #--------------------------------------------------- sub regexRepeat { my ($sInput, $sOutput) = @_; #----------------------------------------- # add tests here to try out different things # if it doesn't work, change is to isnt #------------------------------------------ #changed is to isnt: #this doesn't work, $input='abcdeee' results in 'ab' isnt(eval {$sInput =~ /(..)/;$1}, $sOutput , q{using /(..)/}); #changed is to isnt: #$input='abcdeee' printed out only 'e' isnt(eval {$sInput =~ /(.)\1/;$1}, $sOutput , q{using /(.)\1/}); #changed is to isnt: #$input='abcdeee' printed out undef isnt(eval {$sInput =~ /((.)\1)/;$2}, $sOutput , q{using /((.)\1)/;$2}); #changed is to isnt: #$input='abcdee' also printed out undef isnt(eval {$sInput =~ /((.)\1)/;$1}, $sOutput , q{using /((.)\1)/;$1}); #BINGO! this worked is(eval {$sInput =~ /(.)(\1+)/;"$1$2"}, $sOutput , q{using /(.)(\1+)/;"$1$2"}); } #============================================================ # HERE IS WHERE I SELECT EXPERIMENTS #============================================================ regexRepeat('abcdeeef', 'eee'); #only one to find regexRepeat('abbb;eeef', 'bbb'); #should find first