P is for Practical | |
PerlMonks |
Formatting dynamic method namesby clinton (Priest) |
on Oct 10, 2009 at 13:29 UTC ( [id://800455]=perlquestion: print w/replies, xml ) | Need Help?? |
clinton has asked for the wisdom of the Perl Monks concerning the following question: Every now and again, I want to set the value of a number of properties on an object from a hash, where the method name is the same as the key name, but with a prefix, eg
But how to do this for all the keys in a hash? I've thought of two methods:
I prefer the second method, because it is shorter, but (1) it is less readable and (2) Perl::Tidy reformats it with a space before the arrow, which still works, but looks rather odd:
Which method would you prefer? One of the above, or some other syntax? (Note: I benchmarked the difference between these two, and while the temp var is slightly faster, the difference is negligible.)
Update: corrected a typo in Method 2, thanks to zwon for pointing it out
Back to
Seekers of Perl Wisdom
|
|