Faster perl operation?

Joshua Zeidner jjzeidner at gmail.com
Wed Jan 17 22:46:53 MST 2007


On 1/17/07, Jerry Davis <jdawgaz at cox.net> wrote:
>
> On Wednesday 17 January 2007 19:34, Kevin Brown wrote:
> > I'm working on a small script (so far only about 1000 lines long) and
> > I'm finding that I'd like a faster way to do:
> >
> > $variable = "." x ($start - 1);
> >
> > which is incredibly slow since it is creating sometimes on the order of
> > 100,000 to 3,000,000 (yes, Million) periods to fill up the needed
> string.
>
> if you do this more than once in the code, or in a loop;
> why don't you set up a variable at the top of your program that has the
> needed
> dots for the maximum number you would need -- lets say 3,000,000.
>
> then wherever you want n number of dots, just do $variable = substr($dots,
> 1,
> n). this should be much faster.



  Jerry, I had the same idea, but are you sure that this operation will not
allocate a new buffer and copy the entire string( essentially eliminating
the benefit )?

  jmz


jerry
>
> >
> > I've tried using:
> > sprintf +("%s" x ($start - 1)), ".";
> >
> > but I must not have the syntax correct as it doesn't create the needed
> > "." characters.
> >
> > Any thoughts on what is wrong with the sprintf syntax or what else I
> > could try to speed this up?
> > ---------------------------------------------------
> > PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> > To subscribe, unsubscribe, or to change  you mail settings:
> > http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
> --
> Happy Trails!
> Jerry
>
> Hobbit Name: Pimpernel Loamsdown
> Registered Linux User: 275424
>
> This email's random fortune:
> Harp not on that string.
>                 -- William Shakespeare, "Henry VI"
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change  you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>



-- 
.0000. communication.
.0001. development.
.0010. strategy.
.0100. appeal.

JOSHUA M. ZEIDNER
IT Consultant

++power; ++perspective; ++possibilities;
( 602 ) 490 8006
jjzeidner at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.PLUG.phoenix.az.us/pipermail/plug-discuss/attachments/20070117/be4bf6f1/attachment.htm 


More information about the PLUG-discuss mailing list