On 4/29/10 Thu Apr 29, 2010 2:06 PM, "Harry Putnam" <rea...@newsguy.com> scribbled:
> "John W. Krahn" <jwkr...@shaw.ca> writes: > > [...] > >>> In other words is the perl interpreter working harder in one case? >> >> Yes. > > Thanks. Do you have any idea how much worse it is? > > I ask because I have some old scripts that go spinning thru the whole > hash in that same way, that I should probably track down and change > ... They've worked when I used them... but I never checked about how > much overhead they incurred. And they are not used that often either. The best way to see how much time is being taken to perform your program is to measure it yourself. The simplest way is to use a stopwatch. For more sophisticated metrics, sprinkle statements that save the current time in your program: my $t1 = time(); and print out the time at the beginning and the end of your program. If you have a subroutine you want to measure, use the Benchmark module, but that takes a little effort to get a good value. The general advice is not to worry about execution time until it becomes an issue. In other words, just get your program to do what you want it to do, then try to speed it up only if it is taking too long. You will get lots of advice here and elsewhere about using efficient programming methods. While it is good to write efficient programs, there are other aspects of programming that are usually more important: accuracy, reliability, and maintainability come to mind. There is always a tradeoff of programmer time and computer time in programming, and it is usually the case that programmer time is the more valuable quantity. >>> I'm not sure what roll the `++' plays there either. >> >> That is incrementing the value in $data{ $_ }{ $r2 }. > > I guess I should have asked why is it incrementing that data and why > is $r2 in squiggly brackets? The braces ({}) mean that %data is a "hash-of-hashes", i.e., the values of the elements of %data are references to hashes. The '++' is counting the number of times that the primary key $_ and secondary key $r2 occur when that line is executed. Your program may be interested in the actual number, or it may just be interested that the key combination appeared at all (you didn't include enough context to tell.) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/