in reply to Re^4: Wrong Error Message When Testing for Failure of Constructor
in thread Wrong Error Message When Testing for Failure of Constructor
Even though I'm convinced that proper copying would have solved the problem, I think that the idea of having subroutine return a brand-new lexical every time the defaults are needed is far preferable; I wish I had proposed it myself.
That said, this code has some unwarranted inefficiencies:
Here the sub default_values generates a new hash, but then it returns a copy of it. That's doing twice the work. The assignment to the variable is also unnecessary work. I.e., just do this:sub default_values { my %default_values = ( SUBJECT => 'Subject (<= 44 characters) goes here', AUTHOR => { NAME => 'A. U. Thor', CPANID => 'AUTHOR', WEBSITE => 'http://a.galaxy.far.far.away/modules' +, EMAIL => 'a.u.thor@a.galaxy.far.far.away', }, ); return { %default_values }; }
sub default_values { return +{ SUBJECT => 'Subject (<= 44 characters) goes here', AUTHOR => { NAME => 'A. U. Thor', CPANID => 'AUTHOR', WEBSITE => 'http://a.galaxy.far.far.away/modules' +, EMAIL => 'a.u.thor@a.galaxy.far.far.away', }, }; }
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Wrong Error Message When Testing for Failure of Constructor
by jkeenan1 (Deacon) on Jul 24, 2005 at 01:40 UTC |