I am maintaining a script that does this:
sub setLineBreak {
my $inFile = shift;
$/ = "\n";
open( IN, "<$inFile" ) or die "Cannot open $inFile: $!\n";
while (<IN>) {
if ( $_ =~ /\r\n/ ) {
print "DOS line breaks detected ...\n" if ($verbose);
$/ = "\r\n";
last;
}
elsif ( $_ =~ /\r/ ) {
print "Mac line breaks detected ...\n" if ($verbose);
$/ = "\r";
last;
}
else {
print "Unix line breaks detected ...\n" if ($verbose);
$/ = "\n";
last;
}
}
close IN;
}
The idea is that the input line separator needs to be detected and $/ is then adjusted accordingly. If all you do, subsequently, is open the file, and do:
while(<FILE>){
chomp;
# etc.
}
then I don't think that while $/ adjustment thing is necessary. I for one have never seen such a check before. I'm tempted to just remove the whole sub. Why shouldn't I?
Thanks!
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.