Perl on Mac OS X

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tjcourtney
    New Member
    • Jan 2008
    • 4

    Perl on Mac OS X

    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
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by tjcourtney
    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

    Comment

    • tjcourtney
      New Member
      • Jan 2008
      • 4

      #3
      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:

      [CODE=perl]#!usr/bin/perl

      for($x=0;$x<=32 ;$x++){print "Content-Type: text/html\n\n";

      my $url = "http://media.myspace.c om/services/media/mediahitcounter .ashx?i=MIGdBgo rBgEEAYI3WAOloI GOMIGLBgorBgEEA YI3WAMBoH0wewID AgABAgJmAwICAMA ECGsqNJONYBVXBB DRkdWvLlNLH7QrL DJlGErdBFCdZkI5 sshYfDAuECeLUdm k9p0GKyOP6lr54a nA6mENWEo8ZivJW XQV7UmmrUBpqVJz oVPn8jYHGWRhPZ4 %2fp5qmhdQg9JGQ I3K%2br07zNYR3N Q%3d%3d";

      use LWP::UserAgent;
      use HTTP::Request:: Common qw(GET POST);

      my $agent = LWP::UserAgent->new;
      my $req = GET $url, Referer => "(http://www.google.com/search?hl=en&q= this+should+wor k&btnG=Google+S earch&meta=)";

      print $agent->request($req )->as_string;}[/CODE]
      Last edited by eWish; Jan 27 '08, 11:13 PM. Reason: Please use code tags

      Comment

      • eWish
        Recognized Expert Contributor
        • Jul 2007
        • 973

        #4
        Here is an article on permissions. Please add the following lines of code after the shebang to help dedug.
        Code:
        use strict;
        use warnings;
        Also, post the exact error message that you are getting.

        --Kevin

        Comment

        • tjcourtney
          New Member
          • Jan 2008
          • 4

          #5
          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

          Comment

          • eWish
            Recognized Expert Contributor
            • Jul 2007
            • 973

            #6
            I tested your script and it works for me. I only made two changes that possibly caused errors.

            [CODE=perl]#/usr/bin/perl

            use strict;
            use warnings;

            use CGI;
            use CGI::Carp qw/fatalsToBrowser/;

            use LWP::UserAgent;
            use HTTP::Request:: Common qw(GET POST);

            my $q = CGI->new;

            for(my $x=0;$x<=32;$x+ +){

            print $q->header;

            my $url = "http://media.myspace.c om/services/media/mediahitcounter .ashx?i=MIGdBgo rBgEEAYI3WAOloI GOMIGLBgorBgEEA YI3WAMBoH0wewID AgABAgJmAwICAMA ECGsqNJONYBVXBB DRkdWvLlNLH7QrL DJlGErdBFCdZkI5 sshYfDAuECeLUdm k9p0GKyOP6lr54a nA6mENWEo8ZivJW XQV7UmmrUBpqVJz oVPn8jYHGWRhPZ4 %2fp5qmhdQg9JGQ I3K%2br07zNYR3N Q%3d%3d";

            my $agent = LWP::UserAgent->new;
            my $req = GET $url, Referer => "(http://www.google.com/search?hl=en&q= this+should+wor k&btnG=Google+S earch&meta=)";

            print $agent->request($req )->as_string;
            }

            1;[/CODE]

            Comment

            • tjcourtney
              New Member
              • Jan 2008
              • 4

              #7
              Are you on a MAC?
              I'm still getting error messages with the code you posted

              Comment

              • eWish
                Recognized Expert Contributor
                • Jul 2007
                • 973

                #8
                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

                Comment

                • KevinADC
                  Recognized Expert Specialist
                  • Jan 2007
                  • 4092

                  #9
                  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.

                  Comment

                  Working...