In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/e6ebbe921e63dbd445aa30e30a0b2b80574b88a0?hp=e2ec1b05ae07740bd4d51ac9fc407d6f104f7172>
- Log ----------------------------------------------------------------- commit e6ebbe921e63dbd445aa30e30a0b2b80574b88a0 Author: Shlomi Fish <[email protected]> Date: Thu Oct 16 12:25:30 2014 +0300 perlfork.pod: convert "\t"s to spaces. For: RT #122987 (second part) M pod/perlfork.pod commit 0e3be540c5c5d8ec7d6c682091855e8865b99b51 Author: Shlomi Fish <[email protected]> Date: Thu Oct 16 12:20:22 2014 +0300 Remove trailing whitespace. For: RT #122987 (first part) M pod/perlfork.pod commit 5566fa1536b7e3ab06bf74ce785d42d16c663791 Author: Shlomi Fish <[email protected]> Date: Thu Oct 16 11:43:06 2014 +0300 Convert "\t"s to spaces in perlref.pod. For: RT #122986 M pod/perlref.pod ----------------------------------------------------------------------- Summary of changes: pod/perlfork.pod | 80 ++++++++++++++++++++++++++++---------------------------- pod/perlref.pod | 60 +++++++++++++++++++++--------------------- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/pod/perlfork.pod b/pod/perlfork.pod index fed58f3..c118fb5 100644 --- a/pod/perlfork.pod +++ b/pod/perlfork.pod @@ -168,8 +168,8 @@ BEGIN block, but will not continue parsing the source stream after the BEGIN block. For example, consider the following code: BEGIN { - fork and exit; # fork child and exit the parent - print "inner\n"; + fork and exit; # fork child and exit the parent + print "inner\n"; } print "outer\n"; @@ -198,7 +198,7 @@ separately in the child. On some operating systems, notably Solaris and Unixware, calling C<exit()> from a child process will flush and close open filehandles in the parent, thereby corrupting the filehandles. On these systems, calling C<_exit()> -is suggested instead. C<_exit()> is available in Perl through the +is suggested instead. C<_exit()> is available in Perl through the C<POSIX> module. Please consult your system's manpages for more information on this. @@ -224,63 +224,63 @@ write to a forked child: # simulate open(FOO, "|-") sub pipe_to_fork ($) { - my $parent = shift; - pipe my $child, $parent or die; - my $pid = fork(); - die "fork() failed: $!" unless defined $pid; - if ($pid) { - close $child; - } - else { - close $parent; - open(STDIN, "<&=" . fileno($child)) or die; - } - $pid; + my $parent = shift; + pipe my $child, $parent or die; + my $pid = fork(); + die "fork() failed: $!" unless defined $pid; + if ($pid) { + close $child; + } + else { + close $parent; + open(STDIN, "<&=" . fileno($child)) or die; + } + $pid; } if (pipe_to_fork('FOO')) { - # parent - print FOO "pipe_to_fork\n"; - close FOO; + # parent + print FOO "pipe_to_fork\n"; + close FOO; } else { - # child - while (<STDIN>) { print; } - exit(0); + # child + while (<STDIN>) { print; } + exit(0); } And this one reads from the child: # simulate open(FOO, "-|") sub pipe_from_fork ($) { - my $parent = shift; - pipe $parent, my $child or die; - my $pid = fork(); - die "fork() failed: $!" unless defined $pid; - if ($pid) { - close $child; - } - else { - close $parent; - open(STDOUT, ">&=" . fileno($child)) or die; - } - $pid; + my $parent = shift; + pipe $parent, my $child or die; + my $pid = fork(); + die "fork() failed: $!" unless defined $pid; + if ($pid) { + close $child; + } + else { + close $parent; + open(STDOUT, ">&=" . fileno($child)) or die; + } + $pid; } if (pipe_from_fork('BAR')) { - # parent - while (<BAR>) { print; } - close BAR; + # parent + while (<BAR>) { print; } + close BAR; } else { - # child - print "pipe_from_fork\n"; - exit(0); + # child + print "pipe_from_fork\n"; + exit(0); } Forking pipe open() constructs will be supported in future. -=item Global state maintained by XSUBs +=item Global state maintained by XSUBs External subroutines (XSUBs) that maintain their own global state may not work correctly. Such XSUBs will either need to maintain locks to diff --git a/pod/perlref.pod b/pod/perlref.pod index a165dbc..86ecfdd 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -107,7 +107,7 @@ as using square brackets--instead it's the same as creating a list of references! @list = (\$a, \@b, \%c); - @list = \($a, @b, %c); # same thing! + @list = \($a, @b, %c); # same thing! As a special case, C<\(@foo)> returns a list of references to the contents of C<@foo>, not a reference to C<@foo> itself. Likewise for C<%foo>, @@ -122,8 +122,8 @@ A reference to an anonymous hash can be created using curly brackets: $hashref = { - 'Adam' => 'Eve', - 'Clyde' => 'Bonnie', + 'Adam' => 'Eve', + 'Clyde' => 'Bonnie', }; Anonymous hash and array composers like these can be intermixed freely to @@ -190,8 +190,8 @@ template without using eval(). Here's a small example of how closures work: sub newprint { - my $x = shift; - return sub { my $y = shift; print "$x, $y!\n"; }; + my $x = shift; + return sub { my $y = shift; print "$x, $y!\n"; }; } $h = newprint("Howdy"); $g = newprint("Greetings"); @@ -297,20 +297,20 @@ and directory handles, though.) However, if you assign the incoming value to a scalar instead of a typeglob as we do in the examples below, there's no risk of that happening. - splutter(*STDOUT); # pass the whole glob - splutter(*STDOUT{IO}); # pass both file and dir handles + splutter(*STDOUT); # pass the whole glob + splutter(*STDOUT{IO}); # pass both file and dir handles sub splutter { - my $fh = shift; - print $fh "her um well a hmmm\n"; + my $fh = shift; + print $fh "her um well a hmmm\n"; } - $rec = get_rec(*STDIN); # pass the whole glob + $rec = get_rec(*STDIN); # pass the whole glob $rec = get_rec(*STDIN{IO}); # pass both file and dir handles sub get_rec { - my $fh = shift; - return scalar <$fh>; + my $fh = shift; + return scalar <$fh>; } =back @@ -365,7 +365,7 @@ Admittedly, it's a little silly to use the curlies in this case, but the BLOCK can contain any arbitrary expression, in particular, subscripted expressions: - &{ $dispatch{$index} }(1,2,3); # call correct routine + &{ $dispatch{$index} }(1,2,3); # call correct routine Because of being able to omit the curlies for the simple case of C<$$x>, people often make the mistake of viewing the dereferencing symbols as @@ -374,10 +374,10 @@ though, you could use parentheses instead of braces. That's not the case. Consider the difference below; case 0 is a short-hand version of case 1, I<not> case 2: - $$hashref{"KEY"} = "VALUE"; # CASE 0 - ${$hashref}{"KEY"} = "VALUE"; # CASE 1 - ${$hashref{"KEY"}} = "VALUE"; # CASE 2 - ${$hashref->{"KEY"}} = "VALUE"; # CASE 3 + $$hashref{"KEY"} = "VALUE"; # CASE 0 + ${$hashref}{"KEY"} = "VALUE"; # CASE 1 + ${$hashref{"KEY"}} = "VALUE"; # CASE 2 + ${$hashref->{"KEY"}} = "VALUE"; # CASE 3 Case 2 is also deceptive in that you're accessing a variable called %hashref, not dereferencing through $hashref to the hash @@ -440,7 +440,7 @@ numerically to see whether they refer to the same location. X<reference, numeric context> if ($ref1 == $ref2) { # cheap numeric compare of references - print "refs 1 and 2 refer to the same thing\n"; + print "refs 1 and 2 refer to the same thing\n"; } Using a reference as a string produces both its referent's type, @@ -543,14 +543,14 @@ value. People frequently expect it to work like this. So it does. $name = "foo"; - $$name = 1; # Sets $foo - ${$name} = 2; # Sets $foo - ${$name x 2} = 3; # Sets $foofoo - $name->[0] = 4; # Sets $foo[0] - @$name = (); # Clears @foo - &$name(); # Calls &foo() + $$name = 1; # Sets $foo + ${$name} = 2; # Sets $foo + ${$name x 2} = 3; # Sets $foofoo + $name->[0] = 4; # Sets $foo[0] + @$name = (); # Clears @foo + &$name(); # Calls &foo() $pack = "THAT"; - ${"${pack}::$name"} = 5; # Sets $THAT::foo without eval + ${"${pack}::$name"} = 5; # Sets $THAT::foo without eval This is powerful, and slightly dangerous, in that it's possible to intend (with the utmost sincerity) to use a hard reference, and @@ -571,8 +571,8 @@ a symbol table, and thus are invisible to this mechanism. For example: local $value = 10; $ref = "value"; { - my $value = 20; - print $$ref; + my $value = 20; + print $$ref; } This will still print 10, not 20. Remember that local() affects package @@ -602,8 +602,8 @@ construct is I<not> considered to be a symbolic reference when you're using strict refs: use strict 'refs'; - ${ bareword }; # Okay, means $bareword. - ${ "bareword" }; # Error, symbolic reference. + ${ bareword }; # Okay, means $bareword. + ${ "bareword" }; # Error, symbolic reference. Similarly, because of all the subscripting that is done using single words, the same rule applies to any bareword that is used for subscripting a hash. @@ -659,7 +659,7 @@ trying to build. @colors = qw(red blue green yellow orange purple violet); for my $name (@colors) { - no strict 'refs'; # allow symbol table manipulation + no strict 'refs'; # allow symbol table manipulation *$name = *{uc $name} = sub { "<FONT COLOR='$name'>@_</FONT>" }; } -- Perl5 Master Repository
