======================================================================
 Modern::Open áá»ááºáá¾ááºá¸áááºá¸áá½á¾ááº [MY] áá¼ááºáá¬áá¬áá¬
======================================================================

[ 1. Installation / [MY] áá¼ááºáá¬áá¬áá¬ ]

  ááá·áºáá½ááºá¸áá«:
    cpan Modern::Open

  script áá½ááºá¡áá¯á¶á¸áá¼á¯áá«:
    use Modern::Open;

  á¡áá»á­á¯á¸áááºáá±á¬ááºáá¾á¯: open(), opendir(), sysopen(), pipe(), socket(),
                     áá¾áá·áº accept() áá­á¯ autovivification + autodie áá¬á¸áá¾ááºá¸áá¼áá·áº
                     á¡áá¬á¸áá­á¯á¸áááºá Perl 5.005_03 áá¾áá·áºáá±á¬ááºáá­á¯ááºá¸áá¬á¸áá¾ááºá¸áá»á¬á¸áá½ááº
                     မှတ်ချက်: socket() သည် autovivification ကိုထောက်ပံ့သော်လည်း autodie မပြုလုပ်ပါ။
                     á¡áá¯ááºáá¯ááºáááºá

[ 2. open() -- 2-arg ]

  my $fh;
  open($fh, "< file.txt");   # áááºáá«
  open($fh, "> file.txt");   # áá±á¸áá« (override)
  open($fh, ">> file.txt");  # áááºáá¼áá·áºáá«
  open($fh, "+< file.txt");  # áááº/áá±á¸
  open($fh, "cmd |");        # command pipe áá¾áááºáá«
  open($fh, "| cmd");        # command pipe áá­á¯á·áá±á¸áá«

  while (my $line = readline($fh)) { ... }
  print $fh "text\n";
  close($fh);

[ 3. open() -- 3-arg ]

  my $fh;
  open($fh, '<',  "file.txt");   # áááºáá«
  open($fh, '>',  "file.txt");   # áá±á¸áá« (override)
  open($fh, '>>', "file.txt");   # áááºáá¼áá·áºáá«
  open($fh, '+<', "file.txt");   # áááº/áá±á¸
  open($fh, '+>', "file.txt");   # áááº/áá±á¸ (override)
  open($fh, '-|', "cmd");        # command pipe áá¾áááºáá«
  open($fh, '|-', "cmd");        # command pipe áá­á¯á·áá±á¸áá«

[ 4. opendir() ]

  my $dh;
  opendir($dh, "/path/to/dir");
  while (my $e = readdir($dh)) {
      next if $e eq '.' or $e eq '..';
      print "$e\n";
  }
  closedir($dh);

[ 5. sysopen() ]

  use Fcntl qw(O_RDONLY O_WRONLY O_CREAT O_TRUNC);

  my $fh;
  sysopen($fh, "file.txt", O_RDONLY);
  sysopen($fh, "file.txt", O_WRONLY | O_CREAT | O_TRUNC);
  sysopen($fh, "file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);

[ 6. pipe() ]

  my($reader, $writer);
  pipe($reader, $writer);
  if (my $pid = fork()) {
      close($writer);
      while (my $line = readline($reader)) { print $line }
      close($reader);
  } else {
      close($reader);
      print $writer "child process áá¾ áááºá¹ááá¬áá«\n";
      close($writer);
      exit 0;
  }

[ 7. socket() / accept() ]

  use Socket qw(AF_INET SOCK_STREAM sockaddr_in inet_aton);
  my $server;
  socket($server, AF_INET, SOCK_STREAM, 0);
  # မှတ်ချက်: socket() သည် autodie မပြုလုပ်ပါ; return value ကိုကိုယ်တိုင်စစ်ဆေးပါ။
  my $client;
  accept($client, $server);

[ 8. autodie ]

  # void context: áá¡á±á¬ááºáá¼ááºáá«á die
  open($fh, "< no_such_file.txt");   # dies: Can't open(...)

  # return value áá¼áá·áº: áá¡á±á¬ááºáá¼ááºáá«á undef/0
  my $rc = open($fh, "< file.txt");
  unless ($rc) { warn "open áá¡á±á¬ááºáá¼ááºáá«: $!" }

  open(FILE, "< file.txt");   # dies: Bare handle no longer supported

[ 9. Handle ]

  readline($fh)        # áááºáá¼á±á¬ááºá¸áááºáá«
  read($fh, $buf, $n)  # N byte áááºáá«
  print $fh "..."      # áá±á¸áá«
  binmode($fh)         # binary mode
  seek($fh, 0, 0)      # á¡ááá­á¯á·áá½á¬á¸áá«
  tell($fh)            # áááºáá¾á­áá±áá¬
  close($fh)           # áá­ááºáá«
  eof($fh)             # áá­á¯ááºá¡áá¯á¶á¸áááºáá±á¸áá«

[ 10. Compatibility ]

  Perl áá¬á¸áá¾ááºá¸ : 5.005_03 áá¾áá·áºá¡áááº (5.42 á¡áá«á¡áááº)
  ááááºáá±á¬ááºá¸   : Unix, Linux, macOS, Windows (CRLF á¡áá­á¯á¡áá»á±á¬ááº)
  áá¾á®áá­á¯áá¾á¯      : Fcntl (core module)

[ 11. Official resources ]

  Modern::Open (MetaCPAN):
    https://metacpan.org/dist/Modern-Open

  INABA Hitoshi (ina) on CPAN:
    https://metacpan.org/author/INA

======================================================================
