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

Re: [MacPerl] MacPerl and Alpha, "Illegal character \012" SOLVED!



At 01:54 PM -0400 98/10/13, Richard S. Holmes wrote:
>With some older versions of MacPerl I had no problems editing a script
>in Alpha and sending it to MacPerl to run. But no longer -- now I get
>
> # Illegal character \012 (carriage return).
> File 'Untitled'; Line 2
> # (Maybe you didn't strip carriage returns after a network transfer?)
>
>The script was *not* from a network transfer. I downloaded Alpha and
>MacPerl the other day; started both; opened a new document in Alpha;
>set Perl mode; typed 'print "Hello world\n";'; and did "Run the
>buffer" from the Camel menu. I get the aforementioned error.

With MacPerl 5.2.0r4 and Alpha 7.0 I found this problem as well.

Do you have a #!/usr/bin/perl line at the top?

I found the minimum you need to get rid of this error message is just the '#!'.

But, this not an answer. Where is this \012 coming from?

hmmm. lets have a look at the Perl Mode code in:

Alpha Folder:tcl:Modes:Perl Mode:perlMode.tcl


(or something close to that), my version is 3.12 and it has two proc:

#############################################################################
# Take a Perl script and add commands to take the file STDIN as standard
# input and STDOUT as standard output. This allows scripts written as
# Unix command-line filters to be used in the (non-MPW) Mac environment as
# text filters.
#
# If there's already a #! line in the script, then the new commands
# are added after that line. If there was no #! line in the first place,
# one is added, in case MacPerl is set up to require it (can't hurt...)
#
# $filterHeadLen counts the number of lines we add to the top of the
# original script, so that we can allow for it in interpreting error
# messages issued by MacPerl.
#
# *** As of MacPerl 4.1.4, this business is pretty much obsolete ***
#
proc wrapFilterScript {coreScript} {
global PerlmodeVars scriptStart filterHeadLen interpPat

if {[regexp -indices $interpPat $coreScript allofit cmdln]} {
set endPos [lindex $cmdln 1]
set filterHead [string range $coreScript 0 [expr $endPos+1]]
set coreScript [string range $coreScript [expr $endPos+2] end]
set filterHeadLen 0
incr scriptStart [expr [llength [split $filterHead "\n\r"]] -2]
} else {
set filterHead "#!/bin/perl\r\n"
set filterHeadLen 2
}


set script $filterHead
append script $coreScript


# for debugging purposes, save the script on disk
#
writeScript $script
return $script
}

#############################################################################
# Add a #!/bin/perl line to the script if it doesn't contain one already.
# (MacPerl puts up dialog if this line is missing when it expects it,
# hanging the DoScript and leaving us stuck.)
#
proc wrapSelectScript {coreScript} {
global PerlmodeVars scriptStart filterHeadLen interpPat

if {[regexp -indices $interpPat $coreScript allofit cmdln]} {
set endPos [lindex $cmdln 1]
set filterHead [string range $coreScript 0 [expr $endPos+1]]
set script $coreScript
set filterHeadLen 0
incr scriptStart [expr [llength [split $filterHead "\n\r"]] -2]
} else {
set script "#!/bin/perl\r\n"
append script $coreScript
set filterHeadLen 1
}


# for debugging purposes, save the script on disk
#
writeScript $script
return $script
}

I would say this might be the culprit:

set script "#!/bin/perl\r\n"

To fix this I would change it to:

set script "#!/bin/perl\r"

There is another one as well.

Do a find: \r\n

line 1120:
set filterHead "#!/bin/perl\r\n"
line 1148:
set script "#!/bin/perl\r\n"

D'oh!



SUMMARY:
If you are writing Just Another Perl Hack in Alpha and you leave off the #!/usr/bin/perl line then Alpha inserts one for you with an unwelcome guest, a carriage return.

Remove the \n (Yes, the '\n') on each of the following lines in the file:
Alpha Folder:tcl:Modes:Perl Mode:perlMode.tcl

line 1120:
set filterHead "#!/bin/perl\r\n"
line 1148:
set script "#!/bin/perl\r\n"

Save and restart.

Why does the '\n' have to go?

(in octal)
MacPerl Alpha's tcl
\n Newline 015 012
\r Carriage-return 012 015

This is one for the FAQ-O-Matic.

And so I have submitted it to the FAQ-O-Matic:

print "Hello World!\n"; gives "Illegal character \012 (carriage return)." in Alpha
http://freebie.cfcl.com/cgi-bin/macperl/fom?file=16

Someone please give Alpha a better description, I could not reach to any of the Alpha sites to grab better copy.

Also, if posting info like the description I posted for Alpha is not appropriate for the MacPerl FAQ then please tell me.

Corrections gladly accepted,


takeshi yano
--
email: mailto:takyano@pubzone.com


***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch