[Israel.pm] what do you think is best

Shlomi Fish shlomif at iglu.org.il
Wed Nov 24 10:36:47 PST 2010


Hi Chanan,

a few comments on your code.

On Wednesday 24 November 2010 13:46:43 Chanan Berler wrote:
> Hello All,
> 
> I wonder what you all think is best performace (yes, i could do
> benchmark, but thought of asking).
> thanks
> Chanan
> 
> Part1:
> ======
> 
> my @array = (1..200);
> my $step_size = 7;
> 
> while (@array)
> {
>                 my $array_size = scalar(@array);
>                 my $step = ($array_size > ($step_size - 1) )?
> ($step_size - 1): $array_size;
>                 my $chunk = join( ',', splice(@array, 0, $step) );

No need for the $step calculation here, as splice will extract at most $step 
elements - not more. 

>                 print $chunk, "\n";
> }
> 
> 
> Part 2:
> =======
> my @all_bets = (1..200);
> my $cunk_size = 7;

You've misspelt "chunk" here.

> my $bet_txt = join ",", @all_bets;
> $bet_txt .= ",";

> 
> my $cnt = 0;
> my $group;
> while (($group) = $bet_txt =~ /((\d+,){1,$cunk_size})/o)

The second capturing should be a clustering (?:...) that will make it faster. 
Furthermore, don't you want \G and /g here?
> {
> 	print $group . "\n";
> 	$bet_txt = $';#'

Hmmm.... I see your editor is giving you problems with << $' >>.

> 	exit if ($cnt++ == 10);

What is the purpose of $cnt here? It does not exist in the above code.

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


More information about the Perl mailing list