1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

how to use perl

Discussion in 'Mac Programming' started by Corrosive vinyl, Jul 2, 2007.

  1. macrumors 6502

    Corrosive vinyl

    #1
    Sorry for the total newb questions, but gotta start somewhere. I got this cool book called Programming perl and have started weeding through the 1,000 some pages of it. Where can I write and compile this stuff I am learning? Do I need to get Xcode? Also, How can I open apps so I can see the code? I basically am interested in this language and want to implement it.
     
  2. Moderator

    robbieduncan

    Staff Member

    #2
    Perl is not a compiled language (in the traditional sense). Just save plain text files (you can do that with Text Edit) and run them in the Terminal via perl <filename>
     
  3. macrumors 6502

    Corrosive vinyl

    #3
    coolness... so just go to text edit and write out perl stuff like print "howdy, there!"\n then go to terminal and type perl <texteditfile> that is very doable, thanks!
     
  4. Moderator

    robbieduncan

    Staff Member

    #4
    Just make sure TextEdit is in plain text mode. If you have the formatting toolbar find the Format->Make Plain Text command.

    If you want to be able to just type perl <file> make sure you save the file in your home directory (not Documents).

    You can use the cd command to change directories in Terminal to get to wherever you save it.
     
  5. macrumors 68040

    iSee

    #5
    You might also look at getting a text editor that does syntax highlighting for Perl. There are free ones around.

    I don't want to start another "which text editor is better" battle, but I know TextWrangler is a freeware editor with basic Perl syntax highlighting. I found the highlighting very useful as I learned the language.
     
  6. macrumors G3

    #6
    You don't need to type perl on the command line all the time

    Just make the first line of the file be:
    #!/usr/bin/perl

    If the file is called "myscript" then you do:
    chmod u+x myscript

    And just run as:
    myscript
     
  7. Moderator

    robbieduncan

    Staff Member

    #7
    Probably actually as ./myscript unless the OP has added ./ (or the current directory explicitly) to the PATH.
     
  8. macrumors G3

    #8
    You don't add "./", you just add "."
     
  9. Moderator

    robbieduncan

    Staff Member

    #9
    I think you'll find I'm correct and you are wrong. I'm a professional Unix developer.

    Note that with ./ it works and just . it gives the expected command not found?
     
  10. macrumors G3

    #10
    I'm talking about PATH
     
  11. Moderator

    robbieduncan

    Staff Member

    #11
    In which case either will work, but as I clearly typed the whole command it was clear that I was using ./<command> to explicitly run a command in the CWD, and this was not talking about the PATH, that was a separate aside.
     
  12. macrumors G3

    #12
    You said:

    I don't say it won't work. I mean real Unixers just use "."
     
  13. macrumors 6502

    Corrosive vinyl

    #13
    so if i put scripts in documents/myscripts folder i just cd documents/myscripts then do perl "<file>" whatever file that may be and it runs whatever I wrote...
     

Share This Page