[sf-perl] perl on a mac

Walt Sanders wsanders at pacificwebdesign.org
Sun Nov 16 10:15:46 PST 2008

You quite right about the newbie bit, although I've written dozens of  
perl programs and have many websites using them, it has always been  
"get the job done" and 'someday' I'll master the sophistication.  This  
always worked on my PCs, but this Mac thing has me stopped cold.

Here is the top bit of output from Terminal:

Rang:desktop Rang$ perl idpass.cgi
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en- 
<title>ID Yourself</title>
<meta http-equiv="Content-Type" content="text/html;  
charset=iso-8859-1" />
<body bgcolor='#00ffff'  
onLoad='document.regform.name.focus();'><p><br><br><table width='650'  
cellspacing='0' cellpadding='0' border='0'  
align='center'><tr><td><center><a href='indexcm.html'><font size='2'  
color='#ff0000'><b>Return</b></font></a></center><p /><center><font  
size='4'><b>Member's Personal Site Registration</b></font></center><p / 
 ><center><font size='2' color='#ff0000'><b>(&nbsp;Please read and  
follow these instructions carefully!&nbsp;)</b></font></center><p />


The html is mostly done with print commands or with >> sections.  Here  
is the toping:

use strict;
use CGI qw( :standard );
use Fcntl qw( :flock );

print( header() );
print( start_html( 'ID Yourself' ) );

print("<body bgcolor='#00ffff'  


All rather simple minded, but it works fine everywhere if I don't try  
it on my Mac!  If I run something without html, like

      #!/usr/bin/perl -w
      print "Content-type: text/html\n\n";
      print "Hello, world";

it works just fine.  I get just the two lines printed.


On Sunday, at , Dan Lyke wrote:

> On Sun, 16 Nov 2008 07:22:21 -0800
> Walt Sanders <wsanders at pacificwebdesign.org> wrote:
>> Terminal won't run it of course, it just spits that code back at
>> me. But, if I try to run it in a browser, of try to preview it in an
>> editor, it still spits code back at me.  This is any program that
>> runs perfectly fine when I upload it to any one of my ISP servers.
> Right. You need to either:
> 1. Pipe the output to an html file (although you'll need to strip the
> "Content-Type: text/html\n\n" first two lines). For instance:
>   stuff.cgi > output.html
>   perl -npi.bak -e 's/^Content-Type: .*$//;' output.html
>   And then open output.html in your web browser. If this is a Mac, you
>   could do "open output.html", on a Gnome based Linux machine, you'd
>   do "gnome-open output.html". Or, in either machine (or even  
> Windows),
>   you can have that folder opened and double-click on output.html.
> 2. Run this under a web server on your local machine.
>> I can just download any working .cgi or .pl from one of my
>> websites and it won't run on my machine.
> When you say "won't run", what's the *exact* (copied and pasted)  
> output
> you get from one of these programs. Does it look like:
> danlyke at danhplaptop:~$ ./test.pl
> bash: ./test.pl: /usr/share/perl: bad interpreter: No such file or
> directory danlyke at danhplaptop:~$
> If so, then the Perl interpreter on your web server is in a different
> place than on your Mac. However, it's fairly clear that you're a
> relative newbie (no harm in that, just gotta be more specific), so
> phrases like "Doesn't work" and "won't run" don't help us to debug the
> problem for you.
> Dan

More information about the SanFrancisco-pm mailing list