======================================================================
 Perl7::Handy ÚÛÙ¹ Ø´ÛÙ¹                         [UR] Ø§Ø±Ø¯Ù
======================================================================

[ 1. Installation ]

  Ø§ÙØ³Ù¹Ø§Ù Ú©Ø±ÛÚº:
    cpan Perl7::Handy

  Ø§Ø³Ú©Ø±Ù¾Ù¹ ÙÛÚº Ø§Ø³ØªØ¹ÙØ§Ù:
    use Perl7::Handy;

  Ø§Ø«Ø± (Perl 5.010001 Ø§ÙØ± Ø¨Ø¹Ø¯ Ú©Û):
    * use strict               -- ÙØªØºÛØ± Ø§Ø¹ÙØ§Ù ÙØ§Ø²ÙÛ Ú©Ø±ØªØ§ ÛÛ
    * use warnings             -- Ø§ÙØªØ¨Ø§ÛØ§Øª ÙØ¹Ø§Ù Ú©Ø±ØªØ§ ÛÛ
    * no bareword::filehandles -- open(FILE,...) Ø§ÙØ¯Ø§Ø² ÙØ³ØªØ±Ø¯ Ú©Ø±ØªØ§ ÛÛ
    * no multidimensional      -- $hash{a,b} ÙÙÙ Ú©Ù ØºÛØ± ÙØ¹Ø§Ù Ú©Ø±ØªØ§ ÛÛ
    * use feature qw(signatures)  (Perl 5.020+)
    * no feature qw(indirect)     (Perl 5.031009+)

  Ø§Ø«Ø± (Perl 5.005_03 -- 5.008):
    * use strict
    * open/opendir/sysopen/pipe/socket/accept Ø¢Ù¹Ù ÙÛÙÛÙÛÚ©ÛØ´Ù
    # socket() ناکامی پر autodie نہیں کرتا (void context میں false واپس کرتا ہے)
    * tie Ù¾Ø± ÙØ¨ÙÛ $; Ø¬Ø§Ù (Ú©Ø«ÛØ± Ø¬ÛØªÛ ØµÙ ÙÙÙ Ú©Û Ø±ÙÚ© ØªÚ¾Ø§Ù)

[ 2. open() -- autovivification ]

  my $fh;
  open($fh, "< file.txt");   # Ù¾ÚÚ¾ÛÚº
  open($fh, "> file.txt");   # ÙÚ©Ú¾ÛÚº (Ø§ÙÙØ± Ø±Ø§Ø¦Ù¹)
  open($fh, ">> file.txt");  # Ø´Ø§ÙÙ Ú©Ø±ÛÚº
  open($fh, "+< file.txt");  # Ù¾ÚÚ¾ÛÚº/ÙÚ©Ú¾ÛÚº
  while (my $line = readline($fh)) { ... }
  print $fh "text\n";
  close($fh);

  # bareword ÛÛÙÚÙ ÙØ³ØªØ±Ø¯:
  open(FILE, "< file.txt");   # dies: Use of bareword handle in open

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

  my $fh;
  open($fh, '<',  "file.txt");   # Ù¾ÚÚ¾ÛÚº
  open($fh, '>',  "file.txt");   # ÙÚ©Ú¾ÛÚº (Ø§ÙÙØ± Ø±Ø§Ø¦Ù¹)
  open($fh, '>>', "file.txt");   # Ø´Ø§ÙÙ Ú©Ø±ÛÚº
  open($fh, '+<', "file.txt");   # Ù¾ÚÚ¾ÛÚº/ÙÚ©Ú¾ÛÚº
  open($fh, '+>', "file.txt");   # Ù¾ÚÚ¾ÛÚº/ÙÚ©Ú¾ÛÚº (Ø§ÙÙØ± Ø±Ø§Ø¦Ù¹)
  open($fh, '-|', "cmd");        # Ú©ÙØ§ÙÚ Ù¾Ø§Ø¦Ù¾ Ø³Û Ù¾ÚÚ¾ÛÚº
  open($fh, '|-', "cmd");        # Ú©ÙØ§ÙÚ Ù¾Ø§Ø¦Ù¾ ÙÛÚº ÙÚ©Ú¾ÛÚº

[ 4. opendir() / sysopen() ]

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

  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, 0644);

[ 5. 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 "ÚØ§Ø¦ÙÚ Ù¾Ø±ÙØ³ÛØ³ Ø³Û Ø³ÙØ§Ù\n";
      close($writer);
      exit 0;
  }

[ 6. socket() / accept() ]

  use Socket qw(AF_INET SOCK_STREAM sockaddr_in inet_aton);
  my $server;
  socket($server, AF_INET, SOCK_STREAM, 0);
  # نوٹ: socket() ناکامی پر autodie نہیں کرتا؛ واپسی قدر کو صریحاً جانچیں۔
  my $client;
  accept($client, $server);

[ 7. no bareword::filehandles ]

  # bareword ÛÛÙÚÙ ÙØ³ØªØ±Ø¯:
  open(FILE, "< file.txt");    # error: Bareword filehandle
  print FILE "hello\n";        # error: Bareword filehandle

  # ÙÛÚ©Ø³ÛÚ©Ù ÙØªØºÛØ± Ø§Ø³ØªØ¹ÙØ§Ù Ú©Ø±ÛÚº:
  my $fh;
  open($fh, "< file.txt");
  print $fh "hello\n";
  close($fh);

[ 8. no multidimensional ]

  # Ú©Ø«ÛØ± Ø¬ÛØªÛ ÛÛØ´ ÙÙÙ ØºÛØ± ÙØ¹Ø§Ù:
  my %h;
  $h{1,2} = "val";    # error: Use of multidimensional array emulation

  # ÙØ§Ø¶Ø­ Ú©ÙÛØ¯ Ø§Ø³ØªØ¹ÙØ§Ù Ú©Ø±ÛÚº:
  $h{"$x,$y"} = "val";

[ 9. Signatures (Perl 5.020+) ]

  # Ø¯Ø³ØªØ®Ø· Ø®ÙØ¯Ú©Ø§Ø± ÙØ¹Ø§ÙØ ØªØ¬Ø±Ø¨Ø§ØªÛ Ø§ÙØªØ¨Ø§ÛØ§Øª Ø¯Ø¨Ø§Ø¦Û Ú¯Ø¦Û
  use Perl7::Handy;

  sub greet($name) { return "Hello, $name!" }
  sub add($x, $y)  { return $x + $y }

[ 10. no indirect (Perl 5.031009+) ]

  # Ø¨Ø§ÙÙØ§Ø³Ø·Û Ø¢Ø¨Ø¬ÛÚ©Ù¹ ÙØ­Ù ØºÛØ± ÙØ¹Ø§Ù:
  my $obj = new MyClass;   # error: indirect syntax

  # Ø¨Ø±Ø§Û Ø±Ø§Ø³Øª ÙØ­Ù Ø§Ø³ØªØ¹ÙØ§Ù Ú©Ø±ÛÚº:
  my $obj = MyClass->new;

[ 11. CVE-2016-1238 ]

  # Perl7::Handy Ø§Ø³Ù¹Ø§Ø±Ù¹ Ø§Ù¾ Ù¾Ø± @INC Ø³Û ÙÙØ¬ÙØ¯Û ÚØ§Ø¦Ø±ÛÚ©Ù¹Ø±Û ÛÙ¹Ø§ØªØ§ ÛÛÛ
  # BEGIN { pop @INC if $INC[-1] eq '.' }

[ 12. ÙØ±ÚÙ ÙØ·Ø§Ø¨ÙØª ÙÛÙ¹Ø±Ú©Ø³ ]

  Feature              5.005_03  5.006-009  5.010+  5.020+  5.031009+
  -------------------  --------  ---------  ------  ------  ---------
  strict               yes       yes        yes     yes     yes
  warnings             no        yes        yes     yes     yes
  autovivif. open()    yes       yes        yes*    yes*    yes*
  no bareword FH       emulated  emulated   yes     yes     yes
  no multidim.         tie       tie        yes     yes     yes
  signatures           no        no         no      yes     yes
  no indirect          no        no         no      no      yes

[ 13. Official resources ]

  Perl7::Handy (MetaCPAN):
    https://metacpan.org/dist/Perl7-Handy

  bareword::filehandles:
    https://metacpan.org/dist/bareword-filehandles

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

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