title: Perl: Parameters to msgsnd
body: <p>I am maintaining some existing code</p>
  
  <p>I see this fragment:</p>
  
  <pre><code>msgsnd( $mQueue, pack("l! a*", length($msg), $msg), 0) 
                                     || ... error handling ...
  </code></pre>
  
  <p>I would like to understand the call to pack() as the second argument to msgsnd.</p>
  
  <p>I find the following <a href="https://perldoc.perl.org/functions/msgsnd.html" rel="nofollow noreferrer">documentation for msgsend</a></p>
  
  <blockquote>
    <p>Calls the System V IPC function msgsnd to send the message MSG to the
    message queue ID. MSG must begin with the native long integer message
    type, be followed by the length of the actual message, and then
    finally the message itself. This kind of packing can be achieved with
    pack("l! a*", $type, $message) . Returns true if successful, false on
    error. See also SysV IPC in perlipc and the documentation for
    IPC::SysV and IPC::Msg .</p>
  </blockquote>
  
  <p>This gives the second parameter to pack as $type, but does not explain what $type is. The code I'm trying to understand instead passes the message length.</p>
  
  <p>What's going on? So far as I can tell the existing code is working reliably.</p>