X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlopentut.pod;h=3116f785c17beab22d234ed9e03a7f32ec354eea;hb=cdd94ca776dceea28cef3714a8bc6d873614b2bf;hp=f2ba7cdf6ca77198257600997f02b5c8b3074381;hpb=00dcde61acd9f4256cd0fce5c72bb9ee25e562b3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlopentut.pod b/pod/perlopentut.pod index f2ba7cd..3116f78 100644 --- a/pod/perlopentut.pod +++ b/pod/perlopentut.pod @@ -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 @@ -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,