On Wed, May 02, 2001 at 11:28:14AM -0700, Ross Larner wrote:
> Hello.  I am attempting to print a string one character at a time.  Right now I am 
>using one while loop with chop to create a new string, the reverse of the original 
>string, then another while loop with chop on the reversed string to print out the 
>characters.  I'm sure there's a more straight-forward way of doing this - any ideas?

For what it's worth two ideas present themselves to me.

------code--------

use Benchmark;

$x = "huzzah!";
$times = shift || 10000;
timethese($times, {
                  splitter => sub {for (split //, $x){ $q = $_ }},
                  substring => sub {for (0..length($x) - 1){$q = $_ }}
});

-----end code----

Which results in:

~ 14:44:14$ perl testchar.pl 500000
Benchmark: timing 500000 iterations of splitter, substring...
  splitter: 10 wallclock secs ( 8.96 usr +  0.00 sys =  8.96 CPU)
   substring:  5 wallclock secs ( 4.35 usr +  0.00 sys =  4.35 CPU)

Go wild.  :-)

dha

-- 
David H. Adler - <[EMAIL PROTECTED]> - http://www.panix.com/~dha/
All I felt was his fear...  And the exploding eyeballs.  Did I mention
I hate this gig?   - Cordelia Chase

Reply via email to