Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
There isn't an end-of-file character, per-se. You can cause the other end of a socket to detect an EOF by closing the socket. When the other end finishes reading what you wrote eof(SOCKET) will return true.

If you need the other end to read multiple files then you'll need to rely on some convention. Personally I prefer to prefix potentially long transmissions with the size of the transmission rather than relying a special character which could someday appear by accident in the data stream. For example on the sending side:

  print WRITER length($yaml), "\n", $yaml;

Then the reader can do:

my $length = <READER>; chomp($length); my $buffer = ""; while(length $buffer < $length and not eof(READER)) { read(READER, $buffer, 4048, length $buffer); } # do something with the YAML data in buffer...

Possibly interesting side-note - I was just reading the memcached protocol spec and this is exactly how it works too.


In reply to Re: How to make EOF? by samtregar
in thread How to make EOF? by pileofrogs

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?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-05-29 18:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found