Perl, my old scripts run but a I can't run new scripts

I'm getting back into Perl and I have old practices files which will run fine. But when I write a new script nothing happens. Currently using 10.4.5, BBEdit 6.1 Lite. All my scripts have the following first line: #!/usr/bin/perl
Old scripts work, if I type a new one and run it nothing happens except I get a new command line prompt.

On the other hand if I remove the #!/usr/bin/perl line and go to the command line and type: perl programname. Programname will run!?!!?

I still have to dig into the man pages on perlrun. Does anyone have a clue?

Thanks, Dennis

TiBook, Mac OS X (10.4.5)

Posted on Oct 30, 2006 7:19 PM

Reply
11 replies

Oct 31, 2006 2:25 PM in response to Don MacQueen1

Thank you for replying!!

Each program contains the first line: #!/usr/bin/perl

also the programs have had chmod 755 applied to them

then at the command line I navigate to the directory containing the program,
then I type ./programname
which I understand to mean execute the file in the current directory.

this has always worked in the past and it works with programs I wrote a year ago. It doesn't work with a program I wrote last night.

On the other hand, if I remove the #!... line from the file, I can run the new program by the typing the following at the command line:

perl ./programname.

My reference for all of this is the O'Reilly book Learning Perl

I hope this clarifies what I'm doing.

Thanks

Oct 31, 2006 7:12 PM in response to Dennis Allshouse

When it doesn't work, exactly what message does it give, if any?
(A copy/paste might be good)

What kind of programs that you wrote years ago does it work with? Perl scripts? Compiled C code?

If the old ones are also perl scripts, is their first line also #!/usr/bin/perl ? Are their permissions the same as the new scripts?

I don't know what chmod 755 does, but I do know that chmod +x will tell the shell that it is executable, so that ./programname should work.

Checking for where perl is located, using 'which perl' was a good suggestion.

What editor did you use to create the script? Maybe it has the wrong line endings. Type

wc -l scriptname

and see if the number of lines is what you expect.

Oct 31, 2006 8:55 PM in response to Nils C. Anderson

thanks for all the information. I really appreciate the replies.

all of my experience is based on the O'Reilly book I mentioned above. I've tried to respond to all the comments but the order is not exact.

chmod 755 uses an octal argument to change the permissions on the file.
In particular the file becomes executable.

1. which perl returned /usr/bin/perl which explains why the old perl programs run. Perl is where it's supposed to be.

2. I haven't done anything to my system as far as a rehash goes(what is that anyway?)

3. the wc -l command returned 0 hw2, meaning zero lines, bingo!! this must be it, don't you think?

4. So why will BBEdit let me write, save, reopen files with content and UNIX sees the file as empty.

5. when these programs are run, nothing happens I just get a new prompt.

BTW the program, called hw2, in question reads:

#!/usr/bin/perl
print "hello, world. \n";


get this: when I do cat hw2 I get a listing without the #!/usr/bin/perl at the top ie I see one line instead of two even though wc -l reports zero lines, what's up with that???

I think that's everything for now. I'm going to look for another texteditor

ps does it matter what the line end character is? I can choose Mac or UNIX.

Oct 31, 2006 9:06 PM in response to Dennis Allshouse

In BBEdit choose the unix end of line setting. Save and recheck using the "wc -l" command.

If that doesn't work, things are strange indeed. In that case, use the 'file' command to learn a bit more about the problem script. Here's an example (my file is named "foo")

[1]% cat foo
#!/usr/bin/perl

print "hello\n";
[2]%
[2]% wc -l foo
3 foo
[3]%
[3]% file foo
foo: perl script text executable
[4]%
[4]% ls -l foo
-rwxr-xr-x 1 myname myname 34B Oct 31 19:10 foo*

The key info in the output of the 'file' command is the word 'text'.

rehash is irrelevant when you're trying to execute things using the "./filename" construct.

Nov 1, 2006 8:17 PM in response to Dennis Allshouse

Hi Dennis,
You really should be in the Perl game with a tool like BBEdit. I've stopped saying much about it because it probably does cost too much. However, it's a superb script development environment and since you already own it, you should definitely take advantage of it. The latest version supports text clippings, which is the latest rage. It actually already had essentially the same capability in its Glossary mechanism but it's easier to use in the current form.

BBEdit is also extremely flexible, with a vast array of preferences. In fact I think one warrants your attention. If you are going to use BBEdit to write scripts or edit system files, you want the default line endings to be UNIX, "LF." In BBEdit's preferences, select the "Text Files" pane and under "Default line breaks:", check "UNIX (LF)."
--
Gary
~~~~
They have been at a great feast of languages,
and stolen the scraps.
-- William Shakespeare, "Love's Labour's Lost"

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Perl, my old scripts run but a I can't run new scripts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.