in reply to Re: Pop quiz: find the bug
in thread Pop quiz: find the bug
Nice article, and a nice piece of code. However, there's still something in this piece of code that can be factored out.if (defined $total {$id}) { $total {$id} += $amt; } else { $total {tocredit} += $amt; }
Or, in a more ALGOLish style:$total {exists $total {$id} ? $id : "tocredit"} += $amt;
Note also the use of exists instead of defined; when using exists, we avoid having to initialize all the entries in the hash.(exists $total {$id} ? $total {$id} : $total {tocredit}) += $amt;
Abigail
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Pop quiz: find the bug
by jjohn (Beadle) on Jul 05, 2002 at 05:59 UTC | |
by Abigail-II (Bishop) on Jul 05, 2002 at 09:36 UTC |