Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Using arithmetic division as a substitute for bit manipulation can create unexpected results. Since what you're doing here is shifting bits, why not treat $number like the binary it is? Use the shift right operator >> instead of dividing by two.

(edited to add) Likewise, rather than using arithmetic modulo to to the equivalent of extracting the low bit, just use the bitwise and operator & to do a real bit mask operation. $number & 1 always gives the low bit of an integer $number, $number & 2 the next least significant bit, and so forth.

If personally coding a solution for that specific chore isn't important, see the concise, ready-to-use solutions in this question and answer. I've found that nineteen times out of twenty, consulting Perl Monks Super Search and Google (which often sends me to Perl Monks) brings up a solution ready to drop in as is or use with a little adaptation.

Hope this helps!

In reply to Re: I need help with the error "Modification of non-creatable array value attempted" by Bethany
in thread I need help with the error "Modification of non-creatable array value attempted" by Hramyzn

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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2022-12-03 08:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found