Paul Anderson wrote:
[ snip ]
#!/usr/bin/myperl -w # euler8.pl --- Euler Problem 8 # Author: Paul Anderson<wackyvorlon@paul-andersons-macbook-pro-3.local> # Created: 14 Aug 2012 # Version: 0.01 use warnings; use diagnostics; use 5.16.0; #use strict; no strict; # The number. $numb="731671765313306249192251196744265747423553491949349698352031277 45063262395783180169848018694788518438586156078911294949545950173795833 19528532088055111254069874715852386305071569329096329522744304355766896 64895044524452316173185640309871112172238311362229893423380308135336276 61428280644448664523874930358907296290491560440772390713810515859307960 86670172427121883998797908792274921901699720888093776657273330010533678 81220235421809751254540594752243525849077116705560136048395864467063244 15722155397536978179778461740649551492908625693219784686224828397224137 56570560574902614079729686524145351004748216637048440319989000889524345 06585412275886668811642717147992444292823086346567481391912316282458617 86645835912456652947654568284891288314260769004224219022671055626321111 10937054421750694165896040807198403850962455444362981230987879927244284 90918884580156166097919133875499200524063689912560717606058861164671094 05077541002256983155200055935729725716362695618826704282524836008232575 30420752963450"; $result=0; for ($numb=~/(\d)(\d)(\d)(\d)(\d)/gi) { $cur = $1*$2*$3*$4*$5; # Put the product in a variable. pos $numb=(pos $numb) - 4; # Reset position where matching will begin. # pos $num defaults to the position just # after the *last* character in our match. # We want our second match to begin after # the *first* character. if ( $cur> $result) { $result=$cur; } }
That should be: while ( $numb =~ /(?=(\d)(\d)(\d)(\d)(\d))/g ) { $cur = $1 * $2 * $3 * $4 * $5; $result = $cur if $result < $cur; } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/