I think your logic is somewhat incorrect, nlafferty.

I haven't tested this, but it would appear that if $start_minute was, say 38, to begin with, you'd like to get the value .75, correct? The way your logic is set up, the first elsif will be true (38 >= 7.5), therefore $start_minute will be set to .25 and all logic ends. I doubt this is what you want.

One simple solution would be to change your code like so...

if ($start_minute < 7.5) {$start_minute = .0 ;} elsif ($start_minute >= 7.5 && $start_minute < 22.5) {$start_minute = .25 ;} elsif ($start_minute >= 22.5 && $start_minute < 37.5) {$start_minute = .5 ;} elsif ($start_minute >= 37.5 && $start_minute < 52.5) {$start_minute = .75 ;} elsif ($start_minute >= 52.5) {$start_minute = 1.0 ;}
This should fix your problem. Now, if we look at the case where $start_minute is 38, none of these will be true until you get to the third elsif, which sets $start_minute to .75, which is, I believe, what you want.

Hopefully, this helps,
- Sherlock

Update: Doing conversions using just less thans or greater thans as BikeNomad and HyperZonk have done will make your code simpler but, please note, if you do that, order matters! My suggestion would be to do it that way, though.

Skepticism is the source of knowledge as much as knowledge is the source of skepticism.

In reply to Re: Converting to decimal elsif by Sherlock
in thread Converting to decimal elsif by nlafferty

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.