in reply to Determine whether file is dos or unix format
You might not want to take this snippet as literal, for it will load the entire contents of the file into memory and test the entite thing. This will be quite inneficient. However, this should give you the general idea of how to do what you are looking for.open FILE, 'test_file.txt' || die "$!\n"; my $text = join( '', @{ [ <FILE> ] } ); close FILE; die "The file supplied is not of unix format!\n" if ( $text =~ /\r\n/ +);
This one will only check the first line for Windows format. If it finds it, it will die; otherwise will simply move on with the rest of the application.open FILE, 'test_file.txt' || die "$!\n"; while ( my $line = <FILE> ) { die "File is not of UNIX format!\n" if ( $line =~ /\r\n/ ); last; } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determine whether file is dos or unix format
by ikegami (Patriarch) on Nov 28, 2005 at 21:52 UTC | |
by blazar (Canon) on Nov 29, 2005 at 08:16 UTC | |
by ikegami (Patriarch) on Nov 29, 2005 at 16:16 UTC |