On 1/3/06 1:55 am, "Peter N Lewis" <[EMAIL PROTECTED]> wrote:

> At 17:25 +0000 28/2/06, Adam Witney wrote:
>> Does this work on all platforms? When I try it it works fine on OSX/Linux
>> with MAC/DOS/UNIX line endings, but fails (reads the whole file) when
>> reading DOS line endings on WinXP... Here is my script
>> 
>> use Fcntl;
>> 
>> my $file = $ARGV[0];
>> 
>> open(INFILE, $file) || die "cannot open $file: $!\n";
>> 
>> {
>>  local $/ = get_line_ending_for_file($file);
> 
> Try reading the line ending before opening the file, ie:
> 
> my $temp_line_ending = get_line_ending_for_file($file);
> open(INFILE, $file) || die "cannot open $file: $!\n";
> {
>  local $/ = $temp_line_ending;
> 
> It may be that WinXP is getting confused by opening the file, and
> then sysopen/closing the file in get_line_ending_for_file, and then
> expecting to be able to read from the file.  Not all platforms allow
> you to open the same file multiple times and have independent access
> to it - not that I know anything about WinXP, but old Classic Mac OS
> would quite probably have had problems with this.

Hi Peter,

Unfortunately this doesn't work either, the only way to get it to read the
DOS file properly on WinXP is not to set $/ at all, but of course this
breaks the other platforms

Anyway, I have rewritten it to use sysread to read a chunk at the top of the
file (I only need the header of the file) and process that with a split and
foreach, which seems to be working fine!

Thanks for your help

Adam


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Reply via email to