OSX and Perl Scripts... Please Help!

Posted:
in macOS edited January 2014
Hi All,



I've recently taken up learning Perl, but I've hit a snag that seems to be new with the 10.1.4 update. In order for scripts to run, they must utilize Unix-style line feeds instead of Macintosh carriage returns.



I've tried using BBEdit to add the line feeds, but this doesn't seem to work (I've switched on this option in both the preferences pane and in the options pane that pops up from the Save dialog).



Jutus was kind to suggest the use of Project Builder's "Use Unix Line Endings" feature, but alas, no luck!



As it stands now, when I try to run a script in the terminal, I'm just given a new prompt.



Any thoughts or suggestions would be greatly appreciated.



TIA!

Comments

  • Reply 1 of 12
    [quote]Originally posted by hot cha:

    <strong>Hi All,



    I've recently taken up learning Perl, but I've hit a snag that seems to be new with the 10.1.4 update. In order for scripts to run, they must utilize Unix-style line feeds instead of Macintosh carriage returns.



    I've tried using BBEdit to add the line feeds, but this doesn't seem to work (I've switched on this option in both the preferences pane and in the options pane that pops up from the Save dialog).



    Jutus was kind to suggest the use of Project Builder's "Use Unix Line Endings" feature, but alas, no luck!



    As it stands now, when I try to run a script in the terminal, I'm just given a new prompt.



    Any thoughts or suggestions would be greatly appreciated.



    TIA!</strong><hr></blockquote>



    I use Perl heavily on OS X, and have not

    experienced this difficulty. I use BBEdit, and

    the Unix line endings definitely works fine.



    Do you have a:



    #!/usr/bin/perl -w



    as the first line of your script?



    When you get it working, you can run it right

    inside BBEdit, no need for the terminal (though

    I love it so).



    Also, to run it from the terminal, you'll need

    to:



    chmod 755 yourscript.pl



    or the equivalent.
  • Reply 2 of 12
    hot chahot cha Posts: 37member
    Hi Tom,



    Thanks for your reply.



    I have two versions of BBEdit. An old full copy 5.1 and the lite version for OSX.



    As far as I can tell, the old version (5.1) Perl tools only work with MacPerl. At any rate, the Perl menu refuses to show up when I run this older version.



    The light version doesn't seem to have any capability to run or compile.



    At any rate, I'd rather work in the terminal for now, at least.







    The code is correct (shebang and all) and I have warnings switched on, but I can't even run "Hello, World."



    I've tried:



    chmod 755 myscript.pl



    and



    chmod +x myscript.pl



    to no avail.



    Any other ideas, perhaps?



    Thanks again!
  • Reply 3 of 12
    scott_h_phdscott_h_phd Posts: 448member
    What happens when you script from the command line?
  • Reply 4 of 12
    [quote]Originally posted by hot cha:

    <strong>The code is correct (shebang and all) and I have warnings switched on, but I can't even run "Hello, World."



    I've tried:



    chmod 755 myscript.pl



    and



    chmod +x myscript.pl



    to no avail.



    Any other ideas, perhaps?



    Thanks again!</strong><hr></blockquote>



    Post the code! We'll get to the bottom of this.
  • Reply 5 of 12
    hot chahot cha Posts: 37member
    Hi Scott - Thanks for joining in!



    I haven't tried scripting directly in the terminal. How do I run the script in that situation?



    Tom - Thanks for hangin' in with me.



    #!/usr/bin/perl -w



    print "Hello, World.\

    ";



    The script doesn't show any visible changes after I use the tools in either BBEdit or Project Builder to fix the line feeds. Should it?



    Thanks for your assistance, guys. Much appreciated!
  • Reply 6 of 12
    [quote]Originally posted by hot cha:

    <strong>Hi Scott - Thanks for joining in!



    I haven't tried scripting directly in the terminal. How do I run the script in that situation?



    Tom - Thanks for hangin' in with me.



    #!/usr/bin/perl -w



    print "Hello, World.\

    ";



    The script doesn't show any visible changes after I use the tools in either BBEdit or Project Builder to fix the line feeds. Should it?



    Thanks for your assistance, guys. Much appreciated!</strong><hr></blockquote>



    OK, the code is cool and works fine for me.



    I'm a little confused by your saying 'I haven't tried scripting directly in the terminal. How do I run the script in that situation?"



    How are you running it?



    The way I tested your code was like this:



    copy text from Omniweb

    open Terminal.app

    cat &gt; test.pl

    (paste from menu or command-v)

    control-d

    chmod 755 test.pl

    ./test.pl



    This works fine...



    [ 05-25-2002: Message edited by: Tom Mornini ]</p>
  • Reply 7 of 12
    hot chahot cha Posts: 37member
    Hi Tom,



    The comment about the terminal was a response to Scott's question (at least I thought it was).



    I found my error in the last line of the procedure you outlined.



    I typed test.pl instead of ./test.pl



    I could have sworn I'd tried that!



    At any rate, thanks a *million* for helping me out!
  • Reply 8 of 12
    [quote]Originally posted by hot cha:

    <strong>Hi Tom,



    The comment about the terminal was a response to Scott's question (at least I thought it was).



    I found my error in the last line of the procedure you outlined.



    I typed test.pl instead of ./test.pl



    I could have sworn I'd tried that!



    At any rate, thanks a *million* for helping me out!</strong><hr></blockquote>



    No problem! DOS always tried the current directory for executables, UNIX doesn't. It's a good thing! Prevents new software from installing a trojan into a file called 'ls' (or something else frequently used) when it's unpacked.



    Imagine typing:



    tar xfz newsoftware.tar.gz

    ls



    And having all of your data eliminated because newsoftware.tar.gz produced

    an 'ls' in the same directory that contained:



    #!/bin/sh

    rm -rf ~/* # newbies, don't try this one at home!



    Of course, if you want to subject yourself to such punishment, you can always add '.' to your $PATH environment variable, but I highly recommend against it. :-)
  • Reply 9 of 12
    overtoastyovertoasty Posts: 439member
    Just a quick question ...





    ... if one where to get into a Mac scripting language now (I've just spent the past few years getting seriously into Java)... which is the best way to go?



    Applescript?



    or



    Perl?
  • Reply 10 of 12
    [quote]Originally posted by OverToasty:

    <strong>Just a quick question ...





    ... if one where to get into a Mac scripting language now (I've just spent the past few years getting seriously into Java)... which is the best way to go?



    Applescript?



    or



    Perl?</strong><hr></blockquote>



    Oh, hell, don't ask me!



    I'm the biggest Perl biggot I know! :-)



    Java is 1st class on OS X. Why not use that?



    Applescript Studio is super cool. I'd LOVE to be able to build Cocoa UIs from Perl, and there's a sourceforge <a href="http://camelbones.sourceforge.net/"; target="_blank">project</a> to do just that...and there's also this fascinating <a href="http://dev.perl.org/macosx/"; target="_blank">tidbit</a>!



    [ 05-27-2002: Message edited by: Tom Mornini ]</p>
  • Reply 11 of 12
    gee4orcegee4orce Posts: 165member
    The new O'Reilly book 'Building Cocoa Applications' has a throwaway one-line comment that blew me away:



    "If you're interested in developing Mac OS X applications with Perl, look out for the forthcoming book 'Programming Cocoa Applications with Perl'" <img src="graemlins/surprised.gif" border="0" alt="[Surprised]" />
  • Reply 12 of 12
    bkasaarbkasaar Posts: 9member
    Not to take anything away from this forum, but BareBones has several great lists at <a href="http://www.barebones.com/support/lists.html"; target="_blank">http://www.barebones.com/support/lists.html</a>; (as well as extremely good tech support).

    Lots of Perl geeks and other smart people answer questions about anything remotely related to BBEdit. Just don't mention non-Mac platforms if you don't want to be scolded.
Sign In or Register to comment.