Gossamer Forum
Home : General : Perl Programming :

How to work out number of steps?

Quote Reply
How to work out number of steps?
Ok, I've been playing with this for a while, but the solution has evaded me:(

Basically, I have a 'count' figure. Now, with this figure, I want to work out how many steps I would need to run.

For example;

15023 entries

Each step runs 1000 entries at a time...

I then need to work out how many steps of 1000 at a time I would need to run. i.e

15,023 / 1000 = 15.023. I then need to round this UP to 16, so that all the stages are completed.

Anyone got any ideas? Unsure

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] How to work out number of steps? In reply to
Hi,

my $total = 15023;
my $increment = 1000;
my $steps = int($total / $increment) + 1;

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] How to work out number of steps? In reply to
Aaah.. forgot about the int() function. I was trying to be all clever and use sprintf() Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Alex] How to work out number of steps? In reply to
Hi Alex,

slight correction (for the case when $total % $increment equals 0):

Code:
my $total = 15023;
my $increment = 1000;
my $steps = int($total / $increment);
$steps++ if $total % $increment;

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to work out number of steps? In reply to
Good catch. =)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [yogi] How to work out number of steps? In reply to
Thanks Ivan. I don't think that fix needs to be applied to my script though, as all its going to be doing is something like;

Code:
my $table = $DB->table('Links');
my $count = $table->count( GT::SQL::Condition->new( 'type','NOT LIKE', 'Pay' ) );


my $number_of_steps = int($count / 1000) + 1;

for (my $i = 1; $i <= $number_of_steps; $i++) {
`recip_check.cgi --Destination=$Destination --ID=$i`;
}

... which in effect, will result in the code running something like this (in order);

`recip_check.cgi --Destination=/path/to/admin/folder --ID=1`;
`recip_check.cgi --Destination=/path/to/admin/folder --ID=2`;
`recip_check.cgi --Destination=/path/to/admin/folder --ID=3`;
`recip_check.cgi --Destination=/path/to/admin/folder --ID=4`;
`recip_check.cgi --Destination=/path/to/admin/folder --ID=5`;

If there is an extra step, that shouldn't matter.. as all it will do is skip that stage in recip_check.cgi.

Thanks guys Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!