Re: counting with leading zeros
| From: | Robert Cummings | Date: | Thu, 27 Sep 2007 02:24:14 +0000 |
| Subject: | Re: counting with leading zeros | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262503@lists.php.net to get a copy of this message | ||
On Wed, 2007-09-26 at 19:10 -0400, brian wrote:
> Robert Cummings wrote:
>
> >> Well, this is almost precisely the same thing i have, save for
> >> using POSIX character classes, str_pad instead of sprintf(), and
> >> incrementing elsewhere. What i was really wondering is if there was
> >> a *much simpler* way to do this, not just re-arranging things.
> >
> >
> > You asked for a "Better Way". I gave you a "Better Way". I improved
> > the regex, removed the useless basename() call, performed
> > incrementation in the extraction step, used better function and
> > variable names, and used the str_pad() function because sprintf() is
> > overkill. I also removed your redundant else clause. My version is
> > much simpler. How much is much? You know... much! Other than using a
> > database, it doesn't really get any simpler. Although you obviously
> > have race condition issues also. But that's not getting "simpler".
> > It's getting more correct but also a bit more complex.
> >
>
> Bad day or something?
Nope.
> Did it really seem that i was bitching about your
> response?
Kinda.
> If my response to that gave you the impression i was
> complaining, i assure you that i wasn't. I was simply suggesting
> that i was wondering if there was a *much* simpler way to do this, ie.
> without using several functions to process the filename. Yes, your
> version *does* have some improvements. I'm not disagreeing with you.
> Perhaps i could have been more forthright in my praise for said
> improvements (i'm even going to use some of them--how about that?!)
Well, I'm not looking for praise... but asking a concise question goes a
long way towards meeting your desires.
> >>> Note that the moment you get 100 images the code breaks because
> >>> _100 sorts before _99 and so you will always write over the 100th
> >>> index. To fix this you need to loop through all found files and
> >>> pull the index out and record the highest found.
> >>
> >> For my purposes, if any series gets much beyond 40 i'll have bigger
> >> problems to worry about. I'm content to not worry about overflow
> >> in this case.
> >
> > Suit yourself. But better programmer's don't just wave their hands in
> > the air and hope for the best.
>
> While i agree with you in principle, i'm not interested in that aspect
> of it. The application would have halted *long* before it could reach
> that many. This is why i went to the trouble of pointing this out in the
> original mail. IOW, i'm not stupid; i'm well aware that 100 comes after
> 99 and that it contains 3 digits, not 2, thanks very much.
Nope, 100 comes *before* 99 when lexically sorting.
You must be new around here.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................