Barrie,
Thanks for the interesting benchmarks. In my case, I am only
initializing to '' or 0 to avoid warnings (I have PerlWarn On). What was
most interesting is the hit when you initialize an empty array. I'll
probably just continue on my current course, but the numbers are very
intriguing.
Thanks again.
Drew
Barrie Slaymaker wrote:
>
> Drew Taylor wrote:
> >
> > Does anyone have good evidence either way?
>
> I don't see how C<sub { my $foo ; ...> could ever fail to undef $foo, modulo
> bugs in perl. A hell of a lot of code wouldn't work, then.
>
> My practice is to never init lexicals to undef/(), and only to '' or 0 if
> they might be used before being set to a defined value. Can't see any
> reason to = () in perl, where it's set to undef. C's a different question,
> where you often get randomish values instead of perl's nice clean undef.
>
> Side note: stay away from the dreaded C<my $f = blah if blurgh> idiom
> unless you really understand it and really need it.
>
> Below are some useless benchmarks. The first focuses on the performance of
> C<my $foo=()>, the second is an attempt to put it in perspective. Both
> on perl 5.6.0. It's a lot slower to initialize (66%). My take is that
> it's a minor hit compared to the other things you're usually doing, unless
> you do it in a tight inner loop.
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/