lm@slovax.Eng.Sun.COM (Larry McVoy) (04/06/91)
I ran into a weird bug, I think. I narrowed it down to sysread and/or syswrite. I can't read what I wrote: #!/bin/perl4.000 # open a temp file, write some lines. open(F, ">/tmp/test") || die "create"; $foo = "perl is the greatest!\n"; for $i (0..3) { syswrite(F, $foo, length($foo), $i * length($foo)) || die "write"; } close(F); # reopen a temp file, make sure the lines are the same. open(F, "/tmp/test") || die "create"; for $i (0..3) { sysread(F, $buf, length($foo), $i * length($foo)) || die "read"; if ($buf ne $foo) { print "buf $i is wrong: \"$buf\"\n"; } } close(F); The trace output looks like so: write (3, "perl is the greatest!\n", 22) = 22 write (3, "".., 22) = 22 write (3, "".., 22) = 22 write (3, "".., 22) = 22 read (3, "perl is the greatest!\n", 22) = 22 read (3, "".., 22) = 22 read (3, "".., 22) = 22 read (3, "".., 22) = 22 --- Larry McVoy, Sun Microsystems (415) 336-7627 ...!sun!lm or lm@sun.com
merlyn@iwarp.intel.com (Randal L. Schwartz) (04/07/91)
In article <536@appserv.Eng.Sun.COM>, lm@slovax (Larry McVoy) writes: | syswrite(F, $foo, length($foo), $i * length($foo)) || die "write"; The fourth parameter to syswrite is the offset into $foo, not the offset into the filehandle. You are effectively (on the second and subsequent writes) trying to transfer data from beyond $foo to F. Good thing Perl doesn't let you do that! for (0..24) {syswrite(STDOUT,"Just another Perl hacker,", 1, $_);} -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/