I actually code the other way around. I do for example something like this:
sub foo
{
#takes 2 arguments, a scalar(number between x and y) and a hashref
#make the scalar jump through a hoop
#make a copy of the hash referenced by the hashref
#set the hashref on fire
#multiply each value in the newly created hash by the scalar
#return a reference to said newly created hash
}
And the next step is to actually turn said train of thought into code, which would yield something like this:
sub foo
{
#takes 2 arguments, a scalar(number between x and y) and a hashref
my($scalar, $hashref) = @_;
unless(($scalar =~ /^\d+$/) && ($scalar >= 7) && ($scalar <= 25) &&
+ref($hashref) eq 'HASH'))
{ print "you're an idiot!\n"; return; }
#gee, maybe i could be a little more informative here?
#make the scalar jump through a hoop
make_jump_through_hoop($scalar);
#make a copy of the hash referenced by the hashref
my %newhash = %{$hashref};
#set the hashref on fire
set_on_fire($hashref);
#multiply each value in the newly created hash by the
foreach my $key (keys(%newhash))
{ $newhash{$key} = $newhash{$key} * $scalar; }
#return a reference to said newly created hash
return \%newhash;
}
So in this case(usually when I'm doing something really complicated(for me anyway)) code follows comment, not the other way around.
-
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.
|