in reply to Comments trouble

Not to beat a dead horse or anything but I was able to recreate your problem using Mac OSX 10.2.8 using BBEdit_Lite 6.1. However, the same script when created with vi ran just fine. I opened up the one created in BBEdit with vi and saw the ^M characters had munged the whole works. Also, I turned on warnings and got the following message:
bash-2.05a$ comment.pl
use: bad interpreter: No such file or directoryerl
So the problem is the line endings. There are a couple of ways to clean it up. One (unfortunately not available with OSX version of *nix) is the "unix2dos" command. The other method would be to do some sort of Perl (or sed) script to clean up the control characters. I think if you switch \015 (control-M or Carriage Return) for say \012 (control-L or Line Feed), you should be ok. Something along the lines of say:

#!/usr/bin/perl use warnings; use strict; my $in=$ARGV[0]; my $out=$ARGV[1]; open IN, "$in" or die "Can't do it man. $!"; open OUT, ">>$out" or die "Man, I can't do that. $!"; foreach (<IN>) { s/\015/\012/g; print OUT $_; } close IN; close OUT; exit;

I tried this out and it should do the trick. HTH


"Ex libris un peut de tout"

Replies are listed 'Best First'.
Re: Re: Comments trouble
by ctp (Beadle) on Dec 30, 2003 at 00:14 UTC
    So as we all suspected it was an end of line issue. What confuses me tho is why the semicolon didn't tell the interpreter that that was the end of the line...every other line is "improperly" ended, but the interpreter doesn't seem to care. I guess not all semicolons are created equal? UPDATE - I just re-read some of the previous posts, and I guess a semicolon in a comment is not created equal as it is rendered irrelevant by being in a comment...makes sense.

    What happens when you run the program in the perl debugger?
    Don't know how to do that yet

    Are you using strict and warnings?
    Not yet, but will start. Tried warnings a couple times, but got none, so moved on.
    Had planned on using the shebang as well, but had to stop until I got this worked out. That's actually what tipped me off to the problem.

    If that doesn't work, show us the output, inside <code> tags, of cat -e yourscript, or whatever the equivalent is on MacOS X. That should show any nonprinting...
    I ran the cat -e, and it is in fact the ^M that seems to be in there munging it up.

    However, the same script when created with vi ran just fine.
    yea - I thought of this last night. I started doing my homework in BBedit just because it's a tool I am very used to for other work. I'll get out my little vi pocket ref and dig in...all the vi I ever knew will probably come back to me after a few scripts.

    I do plan on trying to make it work the other way too tho. Many thanks to all who came to my rescue!

    CTP
      As for the Perl debugger, perl -d <scriptname> should get you started. It's quite useful, I've gotten my non-Perl savvy co-workers into the habit of running it whenever they set up one of our Perl scripts. I just got into the habit of using vi because on one system, that was the only editor I had available, so I learned it (the other telling point was when the fstab on my Linux box got messed up and I had to reboot into standalone mode and edit the thing by hand and at that point, vi is all you've got :-). I played a bit with BBEdit and found that if you do a "Save As" and select "Simple Text" and "ASCII" under the options (or advanced options), the file will get saved the way you want it and run just right (discovered that after I posted the script to clean up the CR/LFs. Anyhow, good luck.


      "Ex libris un peut de tout"