Loading ...
Sorry, an error occurred while loading the content.

#! line on Mac

Expand Messages
  • shrdlu2002
    I ve written a couple of dozen Perl scripts and run them in Windows, and occasionally as CGI. Now I m trying to do the same in a Terminal window on a Mac using
    Message 1 of 3 , Apr 25, 2007
    • 0 Attachment
      I've written a couple of dozen Perl scripts and run them in Windows,
      and occasionally as CGI. Now I'm trying to do the same in a Terminal
      window on a Mac using OS X.2 (panther), and I'm stuck.


      In Windows 95, 98, and XP, this is how I start:



      #!C:\Perl\bin\perl.exe
      use CGI qw(:standard) ;
      print header();

      #use strict;
      use warnings;


      # Create a user agent object
      use LWP::UserAgent;
      my $ua = LWP::UserAgent->new;
      $ua->agent("Mozilla/5.0 (PPC Mac OS X; )");

      ...



      I have at least two problems:
      1) I don't know the correct path for the first line, or how to find
      where perl is to be found (my guess is there's no .exe on the Mac). I
      thought in installed perl 5.8, but "perl -v" still says 5.6. There is
      a perl-5.8.1 folder on my desktop, but I don't know how to translate
      that into a Unix-style path, or even if I should be trying.
      2) Sometimes I can get execution started, but it can't find
      UserAgent.pl , which makes me think I'm missing a library. (I probably
      don't have the right Mozilla string, but execution isn't getting that far.

      I'll appreciate any answers, or even semi-educated guesses.



      Thanks,
      Dean
    • John Francini
      Perl on a Mac (assuming you re running Mac OS X) is essentially like running Perl on its native habitat -- that is, UNIX. The magic cookie for Perl on a
      Message 2 of 3 , Apr 25, 2007
      • 0 Attachment
        Perl on a Mac (assuming you're running Mac OS X) is essentially like
        running Perl on its 'native' habitat -- that is, UNIX.

        The "magic cookie" for Perl on a Mac is like it is on most other UNIX
        systems. That is:

        #!/usr/bin/perl


        What version of Mac OS X are you running? My 10.4.9 system has Perl
        5.8.6 installed.


        John


        At 2:50 +0000 4/26/07, shrdlu2002 wrote:
        >I've written a couple of dozen Perl scripts and run them in Windows,
        >and occasionally as CGI. Now I'm trying to do the same in a Terminal
        >window on a Mac using OS X.2 (panther), and I'm stuck.
        >
        >In Windows 95, 98, and XP, this is how I start:
        >
        >#!C:\Perl\bin\perl.exe
        >use CGI qw(:standard) ;
        >print header();
        >
        >#use strict;
        >use warnings;
        >
        ># Create a user agent object
        >use LWP::UserAgent;
        >my $ua = LWP::UserAgent->new;
        >$ua->agent("Mozilla/5.0 (PPC Mac OS X; )");
        >
        >...
        >
        >I have at least two problems:
        >1) I don't know the correct path for the first line, or how to find
        >where perl is to be found (my guess is there's no .exe on the Mac). I
        >thought in installed perl 5.8, but "perl -v" still says 5.6. There is
        >a perl-5.8.1 folder on my desktop, but I don't know how to translate
        >that into a Unix-style path, or even if I should be trying.
        >2) Sometimes I can get execution started, but it can't find
        >UserAgent.pl , which makes me think I'm missing a library. (I probably
        >don't have the right Mozilla string, but execution isn't getting that far.
        >
        >I'll appreciate any answers, or even semi-educated guesses.
        >
        >Thanks,
        >Dean
        >
        >

        --
        John Francini, francini@...

        "The journey is more important than the destination -- that's part of life.
        If you only live for getting to the end, you're almost always disappointed."
        -- Donald Knuth

        [Non-text portions of this message have been removed]
      • Rob Biedenharn
        ... Well, there are two ways to find the location of a program on Unix (and Mac OS X is a Unix). which uses your PATH (try: echo $PATH or env | grep -e
        Message 3 of 3 , Apr 26, 2007
        • 0 Attachment
          On Apr 25, 2007, at 10:50 PM, shrdlu2002 wrote:

          > I've written a couple of dozen Perl scripts and run them in Windows,
          > and occasionally as CGI. Now I'm trying to do the same in a Terminal
          > window on a Mac using OS X.2 (panther), and I'm stuck.
          >
          >
          > In Windows 95, 98, and XP, this is how I start:
          >
          >
          >
          > #!C:\Perl\bin\perl.exe
          > use CGI qw(:standard) ;
          > print header();
          >
          > #use strict;
          > use warnings;
          >
          >
          > # Create a user agent object
          > use LWP::UserAgent;
          > my $ua = LWP::UserAgent->new;
          > $ua->agent("Mozilla/5.0 (PPC Mac OS X; )");
          >
          > ...
          >
          >
          >
          > I have at least two problems:
          > 1) I don't know the correct path for the first line, or how to find
          > where perl is to be found (my guess is there's no .exe on the Mac). I
          > thought in installed perl 5.8, but "perl -v" still says 5.6. There is
          > a perl-5.8.1 folder on my desktop, but I don't know how to translate
          > that into a Unix-style path, or even if I should be trying.

          Well, there are two ways to find the location of a program on Unix
          (and Mac OS X is a Unix).

          'which' uses your PATH (try: "echo $PATH" or "env | grep -e PATH" [no
          quotes, of course]) to find the named program that will actually be
          executed:

          rab:Users/rab $ which perl
          /opt/local/bin/perl
          rab:Users/rab $ perl -v

          This is perl, v5.8.8 built for darwin-2level

          Copyright 1987-2006, Larry Wall

          Perl may be copied only under the terms of either the Artistic
          License or the
          GNU General Public License, which may be found in the Perl 5 source kit.

          Complete documentation for Perl, including FAQ lists, should be found on
          this system using "man perl" or "perldoc perl". If you have access
          to the
          Internet, point your browser at http://www.perl.org/, the Perl Home
          Page.


          'whereis' looks in a number of "standard" directories to find a named
          command:

          rab:Users/rab $ whereis perl
          /usr/bin/perl
          rab:Users/rab $ /usr/bin/perl -v

          This is perl, v5.8.6 built for darwin-thread-multi-2level
          (with 3 registered patches, see perl -V for more detail)

          Copyright 1987-2004, Larry Wall

          Perl may be copied only under the terms of either the Artistic
          License or the
          GNU General Public License, which may be found in the Perl 5 source kit.

          Complete documentation for Perl, including FAQ lists, should be found on
          this system using `man perl' or `perldoc perl'. If you have access
          to the
          Internet, point your browser at http://www.perl.org/, the Perl Home
          Page.

          rab:Users/rab $

          > 2) Sometimes I can get execution started, but it can't find
          > UserAgent.pl , which makes me think I'm missing a library. (I probably
          > don't have the right Mozilla string, but execution isn't getting
          > that far.
          >
          > I'll appreciate any answers, or even semi-educated guesses.
          >
          > Thanks,
          > Dean

          The places that a particular perl will look for libraries is based on
          its value of @INC which is set at compile time of the perl
          interpreter. For the two versions on my system:

          /opt/local/bin/perl (5.8.8) was installed by the `port` command (aka
          MacPorts or DarwinPorts)

          rab:Users/rab $ /opt/local/bin/perl -V | perl -lne 'print if /
          ^Characteristics of/...eof();'
          Characteristics of this binary (from libperl):
          Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO
          Built under darwin
          Compiled at Mar 22 2006 15:47:00
          %ENV:
          PERL5LIB="/usr/local/share/perl/lib/perl5/site_perl"
          @INC:
          /usr/local/share/perl/lib/perl5/site_perl
          /opt/local/lib/perl5/5.8.8/darwin-2level
          /opt/local/lib/perl5/5.8.8
          /opt/local/lib/perl5/site_perl/5.8.8/darwin-2level
          /opt/local/lib/perl5/site_perl/5.8.8
          /opt/local/lib/perl5/site_perl
          /opt/local/lib/perl5/vendor_perl/5.8.8/darwin-2level
          /opt/local/lib/perl5/vendor_perl/5.8.8
          /opt/local/lib/perl5/vendor_perl
          .

          That's rather consistent. The PERL5LIB is set in my environment
          because of work that I was doing for a client and some non-CPAN
          libraries were placed there.

          /usr/bin/perl (5.8.6) is installed as part of the Mac OS X system
          update (I'm on 10.4.9). Note that it looks in a lot more places and
          also looks for platform-version-specific and version-specific
          variants first. I actually hadn't noticed that the /System, /
          Library, and /Network paths weren't part of the /opt/local/bin/perl's
          @INC

          rab:Users/rab $ /usr/bin/perl -V | perl -lne 'print if /
          ^Characteristics of/...eof();'
          Characteristics of this binary (from libperl):
          Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
          PERL_IMPLICIT_CONTEXT
          Locally applied patches:
          23953 - fix for File::Path::rmtree CAN-2004-0452 security issue
          33990 - fix for setuid perl security issues
          SPRINTF0 - fixes for sprintf formatting issues - CVE-2005-3962
          Built under darwin
          Compiled at Nov 1 2006 17:07:31
          %ENV:
          PERL5LIB="/usr/local/share/perl/lib/perl5/site_perl"
          @INC:
          /usr/local/share/perl/lib/perl5/site_perl/5.8.6/darwin-thread-
          multi-2level
          /usr/local/share/perl/lib/perl5/site_perl/5.8.6
          /usr/local/share/perl/lib/perl5/site_perl
          /System/Library/Perl/5.8.6/darwin-thread-multi-2level
          /System/Library/Perl/5.8.6
          /Library/Perl/5.8.6/darwin-thread-multi-2level
          /Library/Perl/5.8.6
          /Library/Perl
          /Network/Library/Perl/5.8.6/darwin-thread-multi-2level
          /Network/Library/Perl/5.8.6
          /Network/Library/Perl
          /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
          /System/Library/Perl/Extras/5.8.6
          /Library/Perl/5.8.1
          .

          So the "best" way to start your perl script on your Mac OS X machine
          is to use the output from:

          $ echo '#!'"$(which perl)"
          #!/opt/local/bin/perl

          (But run the echo command on YOUR system, of course.)

          -Rob

          Rob Biedenharn http://agileconsultingllc.com
          Rob@...





          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.