deprecated has asked for the wisdom of the Perl Monks concerning the following question:
Some of you may recognize my VRML endeavours from my home node. The above code does in fact work. And it's even pretty clear. However, every once in a while a great saint will come along and give me some suggestions that remarkably clarify what I am doing. So here are some things i'd like to clear up:sub simple_properties { my %properties = %{ shift() }; my ($emissive, $diffuse, $shininess, $specular, $transp); foreach my $property (keys %properties) { if ($property eq "emissive") { $emissive = "emissiveColor @{$properties{ $property }} "; } elsif ($property eq "diffuse") { $diffuse = "diffuseColor @{$properties{ $property }} "; } elsif ($property eq "shininess") { $shininess = "shininess @{$properties{ $property }} "; } elsif ($property eq "specular") { $specular = "specularColor @{$properties{ $property }} "; } elsif ($property eq "transparency") { $transp = "transparency @{$properties{ $property }} "; } } return <<"EOR"; appearance Appearance { material Material { $emissive $diffuse $shininess $specular $transp } } EOR }
- I don't like the creation of %properties but I dont see a real good way to do it other than how its being done.
- I also dislike the use of separate strings for interpolation of the arrayrefs. However, I see them as being necessary for understanding the return value. Of course, there is more than one way to do it. I'm hoping somebody can come up with a way that is both simple and clean.
This part kind of irritates me as well. The heredoc here is much clearer. What bothers me though is the creation of the arrays using sort of 'placeholder' values (which japhy understandably hates). The only way I can see to work around this is :sub directional_light { my ($amb_intensity, $color_r, $direction_r, $intensity, $on) = (@_); my @color = @{ $color_r }; my @direction = @{ $direction_r }; $on = etf( $on ); return <<"EOR"; DirectionalLight { ambientIntensity $amb_intensity color @color direction @direction intensity $intensity on $on } EOR }
which I find rather ugly and not particularly clear.my (@array, @other_array) = (@{$_[0]}, @{$_[1]});
Anyhow, I'm particularly exhausted after a long day of hacking at the forthcoming (hopefully) VRML.pm. I hope my fellow monks can shed some light on this and save me a little time in refactoring.
yours truly,
el deppo
--
Laziness, Impatience, Hubris, and Generosity.
|
---|
Replies are listed 'Best First'. | |
---|---|
(dws)Re: Optimizing variable passing (code, peer review)
by dws (Chancellor) on May 11, 2001 at 10:29 UTC | |
Re: Optimizing variable passing (code, peer review)
by perlmonkey (Hermit) on May 11, 2001 at 11:26 UTC | |
Re: Optimizing variable passing (code, peer review)
by Masem (Monsignor) on May 11, 2001 at 07:15 UTC |
Back to
Seekers of Perl Wisdom