======================================================================
 Perl7::Handy à¶ à·à¶§à· à¶´à¶­à·âà¶»à¶º       [SI] à·à·à¶à·à¶½
======================================================================

[ 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 autovivification
    # 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 නොකරයි; return value පැහැදිලිව පරීක්ෂා කරන්න.
  my $client;
  accept($client, $server);

[ 7. no bareword::filehandles ]

  # bareword à·à·à·à¶»à·à· à¶´à·âà¶»à¶­à·à¶à·à·à·à¶´ à¶à·à¶»à·à¶«à·:
  open(FILE, "< file.txt");    # error: Bareword filehandle
  print FILE "hello\n";        # error: Bareword filehandle

  # lexical à·à·à¶ à¶½à·âà¶ºà¶º à¶·à·à·à·à¶­ à¶à¶»à¶±à·à¶±:
  my $fh;
  open($fh, "< file.txt");
  print $fh "hello\n";
  close($fh);

[ 8. no multidimensional ]

  # à¶¶à·à· à¶¸à·à¶± hash à¶à¶±à·à¶à¶»à¶«à¶º à¶à¶à·âà¶»à·à¶º:
  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

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