Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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 }
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:
  • 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.
Here's some more code.
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 }
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 :
my (@array, @other_array) = (@{$_[0]}, @{$_[1]});
which I find rather ugly and not particularly clear.

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.


In reply to Optimizing variable passing (code, peer review) by deprecated

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found