This simple piece of code should do the trick for you...
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/
+);
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.
Update:
I might as well give you an example of something that will be, possibly, a little less memory intensive:
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;
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.
Good Luck!
---hA||ta----
print map{$_.' '}grep{/\w+/}@{[reverse(qw{Perl Code})]} or die while ( 'trying' );
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.