| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
I hope this is the correct list to ask my question - otherwise, please ignore._______________________________________________
I wonder whether anyone could explain the following OS X specific odd behaviour to me. I have the following simple perl script test.pl:
-----------------------------------------
#!/usr/bin/perl
undef $/;
$path = '/path/to/some/file.txt';
open(H, "<$path") || die("Couldn't open file: $path");
while (<H>) {
warn "got here";
$file=$_;
$length = length($file);
warn $length;
}
close(H);
exit(0);
-----------------------------------------
Under linux, this works fine - "undef $/" causes the whole file to be sucked in at once (because no record separator is defined) and $file contains what it would be expected to. I'm aware that it is of course in this case nonsense to put this into a while-loop - but it has brought my attention to the following behaviour under OS X - here's the output I get when running the above script:
got here at test.pl line 9, <H> chunk 1.
20508 at test.pl line 12, <H> chunk 1.
got here at test.pl line 9, <H> chunk 2.
0 at test.pl line 12, <H> chunk 2.
In other words - the while-loop is executed twice. It's as if EOF was different under OS X from Linux but perl doesn't know about it (or something like that?)....
If I change the second line to
$/ = \x04; # (or something else I know that doesn't exist in the file...)
then the while-loop is only executed once.
Any hints, suggestions, etc?
Thanks in advance!
Sebastian
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.
| References: | |
| >while-loop and reading over EOF? (From: Sebastian Hoffmann <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.