473,509 Members | 3,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Perl on Mac OS X

4 New Member
I am not very well versed when it comes to perl. I have a perl script I would like to run. It ran easliy on my roommate's PC after he downloaded activeperl, but on my mac I can't seem to find any way to get it run. I've tried downloading activepearl for Mac OS X and a series of other programs. I've also tried to using terminal, and nothing is working. Any suggestions?

TJ Courtney
Jan 27 '08 #1
8 3526
numberwhun
3,509 Recognized Expert Moderator Specialist
I am not very well versed when it comes to perl. I have a perl script I would like to run. It ran easliy on my roommate's PC after he downloaded activeperl, but on my mac I can't seem to find any way to get it run. I've tried downloading activepearl for Mac OS X and a series of other programs. I've also tried to using terminal, and nothing is working. Any suggestions?

TJ Courtney
Well, this is part of the basics of Perl. The first chapter of most books cover this topic.

Mac OSX is a unix based OS, so, you need to:

1. Ensure that the script has permissions set correctly.
2. Ensure that the first line in your Perl script is the shebang line (ie: #!/usr/bin/perl or whatever the path to your Perl interpreter is on that OS)
3. If 1 and 2 are done, then you should be able to simply type "script.pl" on the command line (where script.pl is the name of your perl script) and it should run.

Regards,

Jeff
Jan 27 '08 #2
tjcourtney
4 New Member
I do have a "shebang" line in the beginning. I'm not really sure what you mean by permissions (I'm really not very good with this stuff) All I know is that the script was originally written for PC, and when I try to run it using textwrangler for MAC I get an error message about it not recognizing the line breaks. It asks if i would like to run anyways, and when I click "yes" two more error messages pop up. Here is the code:

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2.  
  3. for($x=0;$x<=32;$x++){print "Content-Type: text/html\n\n";
  4.  
  5. my $url = "http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAOloIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECGsqNJONYBVXBBDRkdWvLlNLH7QrLDJlGErdBFCdZkI5sshYfDAuECeLUdmk9p0GKyOP6lr54anA6mENWEo8ZivJWXQV7UmmrUBpqVJzoVPn8jYHGWRhPZ4%2fp5qmhdQg9JGQI3K%2br07zNYR3NQ%3d%3d";
  6.  
  7. use LWP::UserAgent;
  8. use HTTP::Request::Common qw(GET POST);
  9.  
  10. my $agent = LWP::UserAgent->new;
  11. my $req = GET $url, Referer => "(http://www.google.com/search?hl=en&q=this+should+work&btnG=Google+Search&meta=)";
  12.  
  13. print $agent->request($req)->as_string;}
Jan 27 '08 #3
eWish
971 Recognized Expert Contributor
Here is an article on permissions. Please add the following lines of code after the shebang to help dedug.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
Also, post the exact error message that you are getting.

--Kevin
Jan 27 '08 #4
tjcourtney
4 New Member
I added those lines of code.
Now, here are the exact error messages I'm getting.
First, before the program allows the script to run I get this error message:

"song1.pl" has non-unix line breaks. #! script interpreters typically require unix line breaks to work properly. Do you wish to run this script anyway?

After I click run, I get these error messages:

Error: File song1.pl; Line 5:
Global symbol "$x" requires explicit package name

Error: File song1.pl; Line 5:
Global symbol "$x" requires explicit package name

Error: File song1.pl; Line 5:
Global symbol "$x" requires explicit package name

Error: File song1.pl; Line 5:
Global symbol "$x" requires explicit package name

Error: File song1.pl; Line 9:
BEGIN not safe after errors--compilation aborted
Jan 27 '08 #5
eWish
971 Recognized Expert Contributor
I tested your script and it works for me. I only made two changes that possibly caused errors.

Expand|Select|Wrap|Line Numbers
  1. #/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI;
  7. use CGI::Carp qw/fatalsToBrowser/;
  8.  
  9. use LWP::UserAgent;
  10. use HTTP::Request::Common qw(GET POST);
  11.  
  12. my $q = CGI->new;
  13.  
  14. for(my $x=0;$x<=32;$x++){
  15.  
  16.     print $q->header;
  17.  
  18.     my $url = "http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAOloIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECGsqNJONYBVXBBDRkdWvLlNLH7QrLDJlGErdBFCdZkI5sshYfDAuECeLUdmk9p0GKyOP6lr54anA6mENWEo8ZivJWXQV7UmmrUBpqVJzoVPn8jYHGWRhPZ4%2fp5qmhdQg9JGQI3K%2br07zNYR3NQ%3d%3d";
  19.  
  20.     my $agent = LWP::UserAgent->new;
  21.     my $req = GET $url, Referer => "(http://www.google.com/search?hl=en&q=this+should+work&btnG=Google+Search&meta=)";
  22.  
  23.     print $agent->request($req)->as_string;
  24. }
  25.  
  26. 1;
Jan 28 '08 #6
tjcourtney
4 New Member
Are you on a MAC?
I'm still getting error messages with the code you posted
Jan 28 '08 #7
eWish
971 Recognized Expert Contributor
The text editor I have allows me to specify the file format. So, I used the MAC line endings (CR). Here is an article that talks about your problems and how to correct them. Look for the "Common Script Mistakes: Line Endings" section. I guess that when I posted the code it did not preserve the newline characters.

--Kevin
Jan 28 '08 #8
KevinADC
4,059 Recognized Expert Specialist
What does that script do? It hits a hit counter and google 32 times? Google does not allow you to hit it's servers using bots anyway, so nobody really should help you with this script.
Jan 28 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
8120
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
31
4724
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
0
9734
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
13
3227
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt...
6
2983
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
4
3671
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the...
21
34327
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
47353
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.