in reply to Re: Ceiling elements of an array!
in thread Ceiling elements of an array!

Ah, I think you're right -- with that light now on, re-reading the OP it makes perfect sense. I guess my intuition circuit is operating in low-power mode today.

Curious why you'd go through the effort of loading POSIXjust to get at ceiling()when, in this context, it's always going to be non-negative numbers and the effect can simply be calculated?

Other than, of course, that the OP did specifically request it . . .

my $eltcnt = @datary; my $dspcnt = int(($eltcnt + 0.5) / 2);

Which could likely be reduced to a single, harder-to-read line of code.

Replies are listed 'Best First'.
Re^3: Ceiling elements of an array!
by AnomalousMonk (Archbishop) on May 06, 2015 at 22:48 UTC
    (the module “in the middle” will be called twice)

    Assuming the above is what is wanted (always an even number of calls), another approach (including efforts of others):

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "my @modules = qw(zero one two three four five six seven); ;; while (@modules) { dd \@modules; my $n = $#modules / 2; print qq{@modules[ 0 .. $n ] -- @modules[ -$n-1 .. -1 ] \n\n}; pop @modules; } " ["zero", "one", "two", "three", "four", "five", "six", "seven"] zero one two three -- four five six seven ["zero", "one", "two", "three", "four", "five", "six"] zero one two three -- three four five six ["zero", "one", "two", "three", "four", "five"] zero one two -- three four five ["zero", "one", "two", "three", "four"] zero one two -- two three four ["zero", "one", "two", "three"] zero one -- two three ["zero", "one", "two"] zero one -- one two ["zero", "one"] zero -- one ["zero"] zero -- zero

    Update: Added '--' marker to output to make partitioning clearer.


    Give a man a fish:  <%-(-(-(-<

Re^3: Ceiling elements of an array!
by GotToBTru (Prior) on May 06, 2015 at 18:13 UTC

    Simpler yet!

    use strict; use warnings; my $modules = shift; my $second_group = int($modules/2); printf "Call %d on port 80, %d on port 8080\n", $modules - $second_group, $second_group;

    Yeah, brain circuits were irrevocably committed to using ceil() in there somewhere, to no real point in a simple case like this.

    Dum Spiro Spero