X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlopentut.pod;h=f023434ed39905ee4c3f8b4453ff2dab81025bd5;hb=58103a2e295c15d87c7ce0bd8dd83d7e110adac4;hp=6d37fb892b9287f2097cfce02ad477e570b6994f;hpb=1a1931329abb89a33c5409dc3da71dd30c04a0b8;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlopentut.pod b/pod/perlopentut.pod index 6d37fb8..f023434 100644 --- a/pod/perlopentut.pod +++ b/pod/perlopentut.pod @@ -67,7 +67,7 @@ examples would effectively mean which is definitely not what you want. The other important thing to notice is that, just as in the shell, -any white space before or after the filename is ignored. This is good, +any whitespace before or after the filename is ignored. This is good, because you wouldn't want these to do different things: open INFO, " mimics the shell in its style of using redirection arrows to specify how to open the file, it -also does so with respect to extra white space around the filename itself +also does so with respect to extra whitespace around the filename itself as well. For accessing files with naughty names, see L<"Dispelling the Dweomer">. @@ -192,11 +192,11 @@ whether it only works on existing files or always clobbers existing ones. open(WTMP, "+< /usr/adm/wtmp") || die "can't open /usr/adm/wtmp: $!"; - open(SCREEN, "+> /tmp/lkscreen") - || die "can't open /tmp/lkscreen: $!"; + open(SCREEN, "+> lkscreen") + || die "can't open lkscreen: $!"; - open(LOGFILE, "+>> /tmp/applog" - || die "can't open /tmp/applog: $!"; + open(LOGFILE, "+>> /var/log/applog" + || die "can't open /var/log/applog: $!"; The first one won't create a new file, and the second one will always clobber an old one. The third one will create a new file if necessary @@ -332,7 +332,7 @@ C takes 3 (or 4) arguments. The HANDLE argument is a filehandle just as with C. The PATH is a literal path, one that doesn't pay attention to any greater-thans or -less-thans or pipes or minuses, nor ignore white space. If it's there, +less-thans or pipes or minuses, nor ignore whitespace. If it's there, it's part of the path. The FLAGS argument contains one or more values derived from the Fcntl module that have been or'd together using the bitwise "|" operator. The final argument, the MASK, is optional; if @@ -364,7 +364,7 @@ added to the sysopen() flags because large files are the default.) Here's how to use C to emulate the simple C calls we had before. We'll omit the C<|| die $!> checks for clarity, but make sure you always check the return values in real code. These aren't quite -the same, since C will trim leading and trailing white space, +the same, since C will trim leading and trailing whitespace, but you'll get the idea. To open a file for reading: @@ -521,7 +521,7 @@ working directory, slash the directory separator, and disallows ASCII NULs within a valid filename. Most systems follow these conventions, including all POSIX systems as well as proprietary Microsoft systems. The only vaguely popular system that doesn't work this way is the -proprietary Macintosh system, which uses a colon where the rest of us +"Classic" Macintosh system, which uses a colon where the rest of us use a slash. Maybe C isn't such a bad idea after all. If you want to use C<< >> processing in a totally boring @@ -602,7 +602,7 @@ welcome to reopen them if you'd like. open(STDOUT, "> output") || die "can't open output: $!"; -And then these can be read directly or passed on to subprocesses. +And then these can be accessed directly or passed on to subprocesses. This makes it look as though the program were initially invoked with those redirections from the command line. @@ -625,11 +625,11 @@ just in a different process: sub head { my $lines = shift || 20; - return unless $pid = open(STDOUT, "|-"); + return if $pid = open(STDOUT, "|-"); # return if parent die "cannot fork: $!" unless defined $pid; while () { - print; last if --$lines < 0; + print; } exit; } @@ -723,7 +723,9 @@ With descriptors that you haven't opened using C, such as sockets, you can set them to be non-blocking using C: use Fcntl; - fcntl(Connection, F_SETFL, O_NONBLOCK) + my $old_flags = fcntl($handle, F_GETFL, 0) + or die "can't get flags: $!"; + fcntl($handle, F_SETFL, $old_flags | O_NONBLOCK) or die "can't set non blocking: $!"; Rather than losing yourself in a morass of twisting, turning Cs, @@ -925,7 +927,7 @@ The two-argument form of C is being used, for example =back -For more detailed discussion about PerlIO see L; +For more detailed discussion about PerlIO see L; for more detailed discussion about Unicode and I/O see L. =head1 SEE ALSO