[Israel.pm] what do you think is best

Chanan Berler bc.other at gmail.com
Wed Nov 24 03:46:43 PST 2010


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) );
                print $chunk, "\n";
}


Part 2:
=======
my @all_bets = (1..200);
my $cunk_size = 7;
my $bet_txt = join ",", @all_bets;
$bet_txt .= ",";

my $cnt = 0;
my $group;
while (($group) = $bet_txt =~ /((\d+,){1,$cunk_size})/o)
{
	print $group . "\n";
	$bet_txt = $';#'
	exit if ($cnt++ == 10);
}

-- 
===================
----     Chanan Berler    ----
===================


More information about the Perl mailing list