Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (4)
    As of 2014-09-15 02:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (145 votes), past polls