[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re[2]: [MacPerl] What am I missing?



At 11:58 AM on 7/29/96, dsmall@mitre.org wrote:

>I set $/ to an unused character because otherwise searches would end with
>each line.  Note that I didn't use an input-output loop, because if my $/
>character is really unused, my program will read the entire file into $test
>in one try.

To read a file completely, you should use
    undef $/;
That works even if the file has the character you think is unused!

At 06:03 96-07-30, Dennis_Drescher@sil.org wrote:

>if ($text =~ /\r/) {
>    $text =~ s/\r//g || die("Ahhh! Couldn't convert to MAC.\n");
>} else {
>    $text =~ s/\n/\n\r/g || die("Ahhh! Couldn't convert to DOS.\n");
>}

PLEASE, use octal when you're looking for a bit pattern -- it's more
portable, and clearer:

$LF = "\012";
$CR = "\015";
$DOSeol = "$CR$LF";
$MacEol = "$CR";
$UNIXeol = "$LF";

if ($text =~ /$DOSeol/o) {
    $text =~ s/$DOSeol/$MacEol/og || die("Ahhh! Couldn't convert to MAC.\n");
} elsif( $text =~ /$UNIXeol/o ) {
    $text =~ s/$UNIXeol/$MacEol/og
        || die("Ahhh! Couldn't convert from Unix.\n");
} else {
    $text =~ s/$MacEol/$DOSeol/og || die("Ahhh! Couldn't convert to DOS.\n");
}

Remember, "\n" does NOT mean ASCII CR!!!!!

--
Hal Wine <hal@dtor.com>