I had some very helpful answers to my question about making a file UNIX compatible.
However, I wanted to see exactly what is in a line of text created in a text editor.
This is because I found in the readme.txt file for DOS2UNIX the following-
MS-DOS and UNIX systems use different methods to identify end-of-line information in text files.
MS-DOS, including Windows 9x/ME/NT/2000, use a carriage return/linefeed pair (CR/LF), whilst UNIX only uses the LF character.
Therefore I wrote the following loop which
1. Reads in each line of a text file
2. Uses split to get each character into an array
3. Prints out the character and ASCII value for each element in the array
For a windows text file, I expected to see at the end of each line and ASCII 10 and an ASCII 11.
All I could see is an ASCII 10.
Where am I doing wrong?
$lcou = 0;
while(defined($linein = <TXTIN>)) {
$lcou += 1;
@chr_array = split(//, $linein);
$linein_tot = scalar(@chr_array);
print "\nline count <$lcou> total chars <$linein_tot> line <$linei
+n>\n";
for($j = 0; $j < $linein_tot; $j ++) {
$chr = $chr_array[$j];
$chr_num = ord($chr);
print "pos <$j> ascii <$chr_num> character <$chr>\n";
}
}
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.