Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Over the last few days, I've been doing a project that is forcing me take a new harder look at everything I've written: code and markup. One of the items which came up in my audit was a little subroutine which takes a number (usually scalar(@list)) and returns how many columns the list would be in according to exponential calculations. The default behavior of this subroutine is to return a word number not an integer. When I looked at it again, a voice in the back of my head told me the subroutine should return the integer by default because integers are more useful. I also had the sinking feeling someone here probably pointed that out to me, and I ignored it. I wanted what I wanted, and no one was going to make me change my mind at the time. I had to change my own mind and pay the price for it later.

So, this is my confession. I am a doofus. I am hard headed and obstinate when it comes to attaining my short term goals. I crawled into my shell to avoid any good advice about coding for the future.

So here is my old sub...

use Lingua::EN::Inflect qw(NUMWORDS); sub get_columns { my ($max_cols, $amount, $number) = @_; if ($amount <= $max_cols ** 2) { for my $num (1..$max_cols) { if ($amount >= $num ** 2 && $amount < ($num + 1) ** 2) { return $number && $number =~ /^[yt1]/ ? $num : NUMWORDS($num); } } } else { return $number && $number =~ /^[yt1]/ ? $max_cols : NUMWORDS($max_ +cols); } }

And the new more useful sub...

use Lingua::EN::Inflect qw(NUMWORDS); sub get_columns { my ($max_cols, $amount, $word) = @_; if ($amount <= $max_cols ** 2) { for my $num (1..$max_cols) { if ($amount >= $num ** 2 && $amount < ($num + 1) ** 2) { return $word && $word =~ /^[yt1]/ ? NUMWORDS($num) : $num; ############################################# Delete to + get rid of Lingua::EN::Inflect } } } else { return $word && $word =~ /^[yt1]/ ? $NUMWORDS($max_cols) : $max_co +ls; ################################################### Delete +to get rid of Lingua::EN::Inflect } }

I feel bad for only now realizing returning a integer by default would be more useful than returning a number word. I think I spoke aloud when I called myself a doofus for returning a number word by default.

I've been doing a lot of rethinks lately. Some of my "utility" scripts seem useless in a broader sense.

The great advice I got from Monks long ago is finally settling into my head. I hope I am better with future advice, but that is to be seen.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to Confession of a hard headed Monk by Lady_Aleena

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 browsing the Monastery: (2)
As of 2024-04-20 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found