home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / IO::Handle.z / IO::Handle
Encoding:
Text File  |  1998-10-30  |  7.6 KB  |  265 lines

  1.  
  2.  
  3.  
  4. IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))                                                    IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      IO::Handle - supply object methods for I/O handles
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.          use IO::Handle;
  13.  
  14.          $fh = new IO::Handle;
  15.          if ($fh->fdopen(fileno(STDIN),"r")) {
  16.              print $fh->getline;
  17.              $fh->close;
  18.          }
  19.  
  20.          $fh = new IO::Handle;
  21.          if ($fh->fdopen(fileno(STDOUT),"w")) {
  22.              $fh->print("Some text\n");
  23.          }
  24.  
  25.          use IO::Handle '_IOLBF';
  26.          $fh->setvbuf($buffer_var, _IOLBF, 1024);
  27.  
  28.          undef $fh;       # automatically closes the file if it's open
  29.  
  30.          autoflush STDOUT 1;
  31.  
  32.  
  33. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  34.      IO::Handle is the base class for all other IO handle classes. It is not
  35.      intended that objects of IO::Handle would be created directly, but
  36.      instead IO::Handle is inherited from by several other classes in the IO
  37.      hierarchy.
  38.  
  39.      If you are reading this documentation, looking for a replacement for the
  40.      FileHandle package, then I suggest you read the documentation for
  41.      IO::File
  42.  
  43.      A IO::Handle object is a reference to a symbol (see the Symbol package)
  44.  
  45. CCCCOOOONNNNSSSSTTTTRRRRUUUUCCCCTTTTOOOORRRR
  46.      new ()
  47.          Creates a new IO::Handle object.
  48.  
  49.      new_from_fd ( FD, MODE )
  50.          Creates a IO::Handle like new does.  It requires two parameters,
  51.          which are passed to the method fdopen; if the fdopen fails, the
  52.          object is destroyed. Otherwise, it is returned to the caller.
  53.  
  54. MMMMEEEETTTTHHHHOOOODDDDSSSS
  55.      See the _p_e_r_l_f_u_n_c manpage for complete descriptions of each of the
  56.      following supported IO::Handle methods, which are just front ends for the
  57.      corresponding built-in functions:
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))                                                    IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))
  71.  
  72.  
  73.  
  74.          close
  75.          fileno
  76.          getc
  77.          eof
  78.          read
  79.          truncate
  80.          stat
  81.          print
  82.          printf
  83.          sysread
  84.          syswrite
  85.  
  86.      See the _p_e_r_l_v_a_r manpage for complete descriptions of each of the
  87.      following supported IO::Handle methods:
  88.  
  89.          autoflush
  90.          output_field_separator
  91.          output_record_separator
  92.          input_record_separator
  93.          input_line_number
  94.          format_page_number
  95.          format_lines_per_page
  96.          format_lines_left
  97.          format_name
  98.          format_top_name
  99.          format_line_break_characters
  100.          format_formfeed
  101.          format_write
  102.  
  103.      Furthermore, for doing normal I/O you might need these:
  104.  
  105.      $fh->fdopen ( FD, MODE )
  106.           fdopen is like an ordinary open except that its first parameter is
  107.           not a filename but rather a file handle name, a IO::Handle object,
  108.           or a file descriptor number.
  109.  
  110.      $fh->opened
  111.           Returns true if the object is currently a valid file descriptor.
  112.  
  113.      $fh->getline
  114.           This works like <$fh> described in the section on _I/_O _O_p_e_r_a_t_o_r_s in
  115.           the _p_e_r_l_o_p manpage except that it's more readable and can be safely
  116.           called in an array context but still returns just one line.
  117.  
  118.      $fh->getlines
  119.           This works like <$fh> when called in an array context to read all
  120.           the remaining lines in a file, except that it's more readable.  It
  121.           will also _c_r_o_a_k() if accidentally called in a scalar context.
  122.  
  123.      $fh->ungetc ( ORD )
  124.           Pushes a character with the given ordinal value back onto the given
  125.           handle's input stream.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))                                                    IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))
  137.  
  138.  
  139.  
  140.      $fh->write ( BUF, LEN [, OFFSET }\] )
  141.           This write is like write found in C, that is it is the opposite of
  142.           read. The wrapper for the perl write function is called
  143.           format_write.
  144.  
  145.      $fh->flush
  146.           Flush the given handle's buffer.
  147.  
  148.      $fh->error
  149.           Returns a true value if the given handle has experienced any errors
  150.           since it was opened or since the last call to clearerr.
  151.  
  152.      $fh->clearerr
  153.           Clear the given handle's error indicator.
  154.  
  155.      If the C functions _s_e_t_b_u_f() and/or _s_e_t_v_b_u_f() are available, then
  156.      IO::Handle::setbuf and IO::Handle::setvbuf set the buffering policy for
  157.      an IO::Handle.  The calling sequences for the Perl functions are the same
  158.      as their C counterparts--including the constants _IOFBF, _IOLBF, and
  159.      _IONBF for _s_e_t_v_b_u_f()--except that the buffer parameter specifies a scalar
  160.      variable to use as a buffer.  WARNING: A variable used as a buffer by
  161.      setbuf or setvbuf must not be modified in any way until the IO::Handle is
  162.      closed or setbuf or setvbuf is called again, or memory corruption may
  163.      result!  Note that you need to import the constants _IOFBF, _IOLBF, and
  164.      _IONBF explicitly.
  165.  
  166.      Lastly, there is a special method for working under ----TTTT and setuid/gid
  167.      scripts:
  168.  
  169.      $fh->untaint
  170.           Marks the object as taint-clean, and as such data read from it will
  171.           also be considered taint-clean. Note that this is a very trusting
  172.           action to take, and appropriate consideration for the data source
  173.           and potential vulnerability should be kept in mind.
  174.  
  175. NNNNOOOOTTTTEEEE
  176.      A IO::Handle object is a GLOB reference. Some modules that inherit from
  177.      IO::Handle may want to keep object related variables in the hash table
  178.      part of the GLOB. In an attempt to prevent modules trampling on each
  179.      other I propose the that any such module should prefix its variables with
  180.      its own name separated by _'s. For example the IO::Socket module keeps a
  181.      timeout variable in 'io_socket_timeout'.
  182.  
  183. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  184.      the _p_e_r_l_f_u_n_c manpage, the section on _I/_O _O_p_e_r_a_t_o_r_s in the _p_e_r_l_o_p manpage,
  185.      the _I_O::_F_i_l_e manpage
  186.  
  187. BBBBUUUUGGGGSSSS
  188.      Due to backwards compatibility, all filehandles resemble objects of class
  189.      IO::Handle, or actually classes derived from that class.  They actually
  190.      aren't.  Which means you can't derive your own class from IO::Handle and
  191.      inherit those methods.
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))                                                    IIIIOOOO::::::::HHHHaaaannnnddddlllleeee((((3333))))
  203.  
  204.  
  205.  
  206. HHHHIIIISSSSTTTTOOOORRRRYYYY
  207.      Derived from FileHandle.pm by Graham Barr <_b_o_d_g@_t_i_u_k._t_i._c_o_m>
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.