By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,253 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,253 IT Pros & Developers. It's quick & easy.

Perl on Mac OS X

P: 4
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
Share this Question
Share on Google+
8 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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

P: 4
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
Expert 100+
P: 971
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

P: 4
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
Expert 100+
P: 971
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

P: 4
Are you on a MAC?
I'm still getting error messages with the code you posted
Jan 28 '08 #7

eWish
Expert 100+
P: 971
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
Expert 2.5K+
P: 4,059
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

Post your reply

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