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

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




Thanks for your help. It turns out that the code I sent wasn't the problem (as
you suspected). The problem was in the print statement. I was using printf
instead of just print. That's what was stripping out the % characters. It was
seeing them as format characters. It didn't take all of them just the first one
in a group. Just what it's suppose to do. What a putz I am! It had nothing to do
with assigning anything to $/. Life's not easy when your green. Thanks for
helping me back on to the straight and narrow path of Perl.

Dennis
_______________________________________________________________________________
Subject: Re: [MacPerl] What am I missing?
From:    dsmall@mitre.org at internet
Date:    07/29/96  2:50 PM

At 11:58 AM on 7/29/96, you wrote:

> This is a newbe type problem but I've got to ask. I'm trying to make a little
> line format changer that goes from PC to Mac and back. It was easy, so I
> thought. Today I discover that my "%" characters are disappearing from my
> text.

I tried your code, and it worked fine (% characters retained), so I suspect
the problem is with some of the surrounding program.  Here is what I used
to test your code:

#!/perl
$/ = "Û"; /* hex A6 -- it may get lost in e-mail */
open (IN, "Testfile") ||
       die("open failed");
$text = <IN>;
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");
}
open (OUT, ">Convertfile") ||
       die("create failed");
print OUT $text;
close (OUT);
close (IN);


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.

Is it possible that you set $/ = "%"?  That would cause the program to
assume that % characters were end-of-lines, and to throw them away on
reading.  If you used an input/output loop, and didn't explicitly restore
the end-of-line character to the print statements, that would give the
results you observed.