Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

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

Add binmode OUT after the open.


  1. you should be using a mode of '>' not '>>', unless your intention is to append to an existing file.
  2. for($i=1;$i<10001;$i++){ is more easily and clearly written as for my $i ( 1 .. 10000 ) {
  3. int(rand(20000))+440000 produces always positive integer.

    If you don't need signed integers, your question would have been much simpler to answer.

  4. $k=substr(pack('l>',$j),1); print OUT $k;

    Packing and writing one value at a time is hugely expensive compared to packing all 10000 values in a single pass and then writing them once.

  5. For goodness sake, use a little horizontal whitespace.

    Don't you find this infinitely more readable?

    #!/usr/bin/perl use strict; print "Content-type: text/html\n\n"; srand(); my $fil = "ch"; open( OUT, '>', $fil ) or die $!; binmode OUT; for my $i ( 1 .. 10_000 ) { my $j = int( rand( 20_000 ) ) + 440_000; my $k = substr( pack( 'l>', $j ), 1 ); print OUT $k; } close( OUT ); print "DONE !";

    Remember that your source code is the equivalent of the professional chef's plated up meal.

    His presentation is what makes the difference between a paid for cover and a decent home cooked meal. It is both his edge and his profit margin.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^4: 3-byte representation by BrowserUk
in thread 3-byte representation by gerleu

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, 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
  • 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (6)
    As of 2015-11-28 14:07 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (742 votes), past polls