in reply to A Set String Length
<Update> SteveAZ98 is right: substr will not pad the string to a fixed length, if it is not longer than the desired width...</Update>print substr($String, 0, 10);
Engaging in one of my favorite PM activities, I benchmarked pack vs. substr:
With these results:timethese(1000000, { pack => q{ my $String = 'Russ is a stud'; $String = pack("A10", $S +tring)}, substr => q{ my $String = 'Russ is a stud'; $String = substr($String +, 0, 10)} });
I just love wasting time with benchmarks, perl golf, etc.Benchmark: timing 1000000 iterations of pack, substr... pack: 7 wallclock secs ( 7.20 usr + 0.00 sys = 7.20 CPU) substr: 6 wallclock secs ( 6.67 usr + 0.01 sys = 6.68 CPU)
Russ
Brainbench 'Most Valuable Professional' for Perl
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: Set String Length (benchmark)
by steveAZ98 (Monk) on Jul 27, 2000 at 08:08 UTC | |
by perlmonkey (Hermit) on Jul 27, 2000 at 08:27 UTC | |
by steveAZ98 (Monk) on Jul 27, 2000 at 08:36 UTC |
In Section
Seekers of Perl Wisdom