======================================================================
 Modern::Open Qo'llanma Varag'i                     [UZ] O'zbek
======================================================================

[ 1. Installation / [UZ] O'zbek ]

  O'rnatish:
    cpan Modern::Open

  Skriptda foydalanish:
    use Modern::Open;

  Ta'sir: open(), opendir(), sysopen(), pipe(), socket(),
          va accept() ni autovivification + autodie versiyalari bilan almashtiradi.
          Perl 5.005_03 va undan keyingi barcha versiyalarda ishlaydi.
          Eslatma: socket() autovivification-ni qo'llab-quvvatlaydi, lekin autodie qilmaydi.

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

  my $fh;
  open($fh, "< file.txt");   # o'qish
  open($fh, "> file.txt");   # yozish (ustiga yozish)
  open($fh, ">> file.txt");  # qo'shish
  open($fh, "+< file.txt");  # o'qish/yozish
  open($fh, "cmd |");        # buyruq pipe'dan o'qish
  open($fh, "| cmd");        # buyruq pipe'ga yozish

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

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

  my $fh;
  open($fh, '<',  "file.txt");   # o'qish
  open($fh, '>',  "file.txt");   # yozish (ustiga yozish)
  open($fh, '>>', "file.txt");   # qo'shish
  open($fh, '+<', "file.txt");   # o'qish/yozish
  open($fh, '+>', "file.txt");   # o'qish/yozish (ustiga yozish)
  open($fh, '-|', "cmd");        # buyruq pipe'dan o'qish
  open($fh, '|-', "cmd");        # buyruq pipe'ga yozish

[ 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 "Bola jarayondan salom\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);
  # Eslatma: socket() autodie qilmaydi; qaytish qiymatini qo'lda tekshiring.
  my $client;
  accept($client, $server);

[ 8. autodie ]

  # void context: muvaffaqiyatsiz bo'lganda die
  open($fh, "< no_such_file.txt");   # dies: Can't open(...)

  # qaytish qiymati bilan: muvaffaqiyatsiz bo'lganda undef/0
  my $rc = open($fh, "< file.txt");
  unless ($rc) { warn "open muvaffaqiyatsiz: $!" }

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

[ 9. Handle ]

  readline($fh)        # bir qatorni o'qish
  read($fh, $buf, $n)  # N bayt o'qish
  print $fh "..."      # yozish
  binmode($fh)         # ikkilik rejim
  seek($fh, 0, 0)      # boshiga o'tish
  tell($fh)            # joriy joylashuv
  close($fh)           # yopish
  eof($fh)             # fayl oxirini tekshirish

[ 10. Compatibility ]

  Perl versiyalari : 5.005_03 va undan yuqori (5.42 ham)
  Platformalar     : Unix, Linux, macOS, Windows (CRLF avtomatik)
  Bog'liqliklar    : Fcntl (asosiy modul)

[ 11. Official resources ]

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

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

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