Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / December 2004



Tip: Looking for answers? Try searching our database.

New to list, greetings and a (newbie)problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Isaac Sherman - 22 Dec 2004 20:53 GMT
Hey all,
I'm new to this list, and I am new to Perl as well.  My primary reason for
learning Perl is in an attempt to automate more tasks in my other programs,
but, it also seems to me to be an interesting language that would increase
my general knowledge as a programmer.

And so it was that I started searching the web for tutorials and the
suchlike.  I came across one,
http://www.ebb.org/PickingUpPerl/pickingUpPerl_toc.html, and decided after a
few chapters to write my own test, just to see how much I'd picked up.
Unfortunately, I'm new to Unix, and am unfamiliar with the terminal.  I
wrote up a pl file in pico, titled hw.pl, and the following is a copy of the
script inside.

#!/usr/bin/perl
use strict;
use warnings;
print "Hello World!\n";

Then, when, in the terminal, I typed: hw.pl while in the same directory, I
got the following message.

tcsh: hw.pl: Command not found.

My meanderings in the Terminal showed that /usr/bin/perl does indeed exist.
I also tried chmod 755 on the file, but didn't change anything.
I'm running the latest version of Panther.

If any of you can let me know what I'm doing wrong, please do.

TIA

Signature

Isaac Sherman
MotaSoft Software
http://www.motaSoftware.com/
Personal Protection Links:
http://www.safetyAndSecurity.us
http://www.m18.us

Allan Juul - 22 Dec 2004 20:58 GMT
> Then, when, in the terminal, I typed: hw.pl while in the same
directory, I
> got the following message.
>
> tcsh: hw.pl: Command not found.

what happens if you type : perl hw.pl

?

./allan
Trey Harris - 22 Dec 2004 21:02 GMT
In a message dated Wed, 22 Dec 2004, Isaac Sherman writes:
> Then, when, in the terminal, I typed: hw.pl while in the same directory, I
> got the following message.
[quoted text clipped - 4 lines]
> I also tried chmod 755 on the file, but didn't change anything.
> I'm running the latest version of Panther.

The chmod was a necessary but not sufficient step.  Your PATH environment
variable does not contain the current directory (".").  You can fix this
one of two ways:

1. setting PATH to include .:
    setenv PATH $PATH:.
  This can be run as a command and will take effect for the current shell
  only, or you can add it to your .cshrc and it will take effect for all
  future shells.

2. Type "./hw.pl" instead of just "hw.pl".

The second is recommended over the first for security reasons, as if
someone were to insert a command in the current directory you might run it
inadvertently.  It's most especially important that ., if it appears in
PATH, always appear last, so that (for instance) someone couldn't drop a
trojan into the current directory which you pick up by mistake rather than
one of the system commands.

Trey
Trey Harris - 22 Dec 2004 21:05 GMT
In a message dated Wed, 22 Dec 2004, Trey Harris writes:
> 1. setting PATH to include .:
>      setenv PATH $PATH:.

Sorry, that should have been
 setenv PATH ${PATH}:.

Sorry, tcsh isn't my primary shell and I confuse the syntax sometimes.
(In bash, zsh, or other Bourne-compatible shells, the syntax would be
 export PATH=$PATH:.
.)

Trey
Isaac Sherman - 22 Dec 2004 21:35 GMT
> In a message dated Wed, 22 Dec 2004, Isaac Sherman writes:
>> Then, when, in the terminal, I typed: hw.pl while in the same directory, I
[quoted text clipped - 5 lines]
>> I also tried chmod 755 on the file, but didn't change anything.
>> I'm running the latest version of Panther.

Wow, thanks for the quick and wide response.  Let's see.  With

> type this:
> perl hw.pl

it works!

Unfortunately, even after setting PATH, it still gives the same error,
whether I type ./hw.pl or just hw.pl.

Hmm.  I can now run scripts in their proper environment.  I just have to use
perl first; could this be a bad thing?

Anyway, thanks a bunch for setting my Perl odyssey on the right track!

Signature

Isaac Sherman
MotaSoft Software
http://www.motaSoftware.com/
Personal Protection Links:
http://www.safetyAndSecurity.us
http://www.m18.us

Conrad Schilbe - 23 Dec 2004 05:25 GMT
> >> tcsh: hw.pl: Command not found.

Welcome to perl on OSX!

perl hw.pl works because perl is in your path and you are giving it hw.pl as
an argument.

> Unfortunately, even after setting PATH, it still gives the same error,
> whether I type ./hw.pl or just hw.pl.

You probably want to be able to just execute your scripts instead of directly
invoking the interpreter. After all - that's what #!/usr/bin/perl is for.

1) Make sure you have execute permissions on your script:
    $ chmod 755 ./hw.pl

2) Find out where perl really is:
    $ which perl

Although I'm certain it should be /usr/bin/perl, perhaps something is
different on you system. The fact that perl hw.pl works indicates that perl
is there and in your path. which will output it's location.

If it is not /usr/bin/perl, you can either change your shebang
(#!/usr/bin/perl) to reflect it's actual location or sym link it:

$ ln -s /path/to/perl /usr/bin/perl

Happy coding!

-- cs
Morbus Iff - 22 Dec 2004 21:04 GMT
> Then, when, in the terminal, I typed: hw.pl while
> in the same directory, I got the following message.
> tcsh: hw.pl: Command not found.

Try "./hw.pl" (no quotes). Most shells and OSs will NOT let you run
scripts in the working (ie. "where I'm currently located") directory
unless you use a relative path or absolute path. This is to prevent you
from accidentally running scripts due to bad typing, garbage text pasted
erroneously, etc.

Signature

Morbus Iff ( you are nothing without your robot car, NOTHING! )
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
Spidering Hacks: http://amazon.com/exec/obidos/ASIN/0596005776/disobeycom
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus

Bill Stephenson - 22 Dec 2004 21:07 GMT
> tcsh: hw.pl: Command not found.

Welcome to "Perl".... I think you're going to learn to love this humble
tool. I sure have.

Anyway, type this:

    perl hw.pl

(ie. type in "perl" before the name of your script.

Bill
John Delacour - 22 Dec 2004 21:36 GMT
>Then, when, in the terminal, I typed: hw.pl while in the same directory, I
>got the following message.
>
>tcsh: hw.pl: Command not found.

As others have said, you can run junk.pl using the command

    perl junk.pl

and this will work even if a) the file is not executable and b) there
is no shebang.

You can also execute the script using

    ./junk.pl

but in this case a) the permissions must be modified to make it
executable and b) you must use the shebang (eg #!/usr/bin/perl).  The
sequence below illustrates the procedure.

JD

bash-2.05a$ cd
bash-2.05a$ echo '#!/usr/bin/perl
 print qq~Hello\n~'  > junk.pl
bash-2.05a$ junk.pl
bash: junk.pl: command not found
bash-2.05a$ perl junk.pl
Hello
bash-2.05a$ ./junk.pl
bash: ./junk.pl: /usr/bin/perl: bad interpreter: Permission denied
bash-2.05a$ chmod 755 junk.pl
bash-2.05a$ ./junk.pl
Hello
bash-2.05a$
Sherm Pendley - 22 Dec 2004 21:48 GMT
> #!/usr/bin/perl
> use strict;
> use warnings;

An excellent start! Always ask Perl for all the help it can give you.

> Then, when, in the terminal, I typed: hw.pl while in the same
> directory, I
[quoted text clipped - 4 lines]
> My meanderings in the Terminal showed that /usr/bin/perl does indeed
> exist.

If it didn't, you'd get a different error:

    -bash: ./test.pl: /usr/bin/perl: bad interpreter: No such file or
directory

As you can see, I'm using bash, but the error you'd get from tcsh would
be similar. The point is that the error message isn't just telling you
that *something* couldn't be found, it's also telling you *what* it
couldn't find - /usr/bin/perl. The message you're getting, on the other
hand, is saying it can't find hw.pl - that's a different error.

> I also tried chmod 755 on the file, but didn't change anything.

Of course not - if the permissions were wrong, you'd get a different
error:

    -bash: ./test.pl: Permission denied

That's not the error you got though, so there's no reason to think that
permissions were the problem.

Okay, what's that leave then? Well, let's review what we know: hw.pl
exists and has the correct perms, but the shell can't find it. Well,
where's the shell looking for it? That's listed in the environment
variable PATH. Show the value for PATH with the 'echo' command:

    Sherm-Pendleys-Computer:~ sherm$ echo $PATH
    /sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

You'll notice that the current directory '.' is not in my PATH. That
means that, if a script is in the current directory, I can't simply
type its name - I'll get the "command not found" error you've seen.
Instead, I have to tell the shell explicitly where to find it, by
including the full path:

    Sherm-Pendleys-Computer:~ sherm$ test.pl
    -bash: test.pl: command not found
    Sherm-Pendleys-Computer:~ sherm$ ./test.pl
    Howdy, world!

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Rick Anderson - 22 Dec 2004 22:31 GMT
> I'm new to this list, and I am new to Perl as well.

Isaac, just judging from your problem, it appears that you're probably
a bit new to all things Unix as well (not trying to sound
condescending, just an observation.) I got on OS X for the first time
two years ago and that's about where I was so I can relate to what
you're going through. I had lots of programming experience, had perl
experience (via MacPerl), was a long time user of the classic Mac OS,
and had a faint smattering of Unix know-how, but I kept running into
odd frustrations like what you describe too because I didn't totally
understand the whole Unix thing. Now I do and it's like a whole other
world (well... it is, but anyway.)

My advice--if my assumption is correct--would be to seek out a few Unix
books. I bought a couple of old Unix beginner books from secondhand
stores and they proved to be worth every penny. Even outdated books on
the topic are fine, anything to get your head around the whole concept
of what's going on and how things like perl interact with the command
line and whatnot. I'm still amazed at how powerful it all is and how I
literally could not do my current job without the sort of understanding
that I have now. It pays off in ways you simply cannot imagine.

--Rick Anderson
"The only difference between me and a madman,
is that I am not mad." -- Salvador Dali
Isaac Sherman - 22 Dec 2004 23:24 GMT
on 12/22/04 5:31 PM, the method -(id)inkswamp1@comcast.net:(id)
sender:@"Rick Anderson"; returned:

>> I'm new to this list, and I am new to Perl as well.
>
> Isaac, just judging from your problem, it appears that you're probably
> a bit new to all things Unix as well (not trying to sound
> condescending, just an observation.)
<snip>
> My advice--if my assumption is correct--would be to seek out a few Unix
> books. I bought a couple of old Unix beginner books from secondhand
[quoted text clipped - 4 lines]
> literally could not do my current job without the sort of understanding
> that I have now. It pays off in ways you simply cannot imagine.

You are absolutely correct; I haven't avoided the command line completely,
but I do have a strong tendency toward using a GUI, and I believe that this
tendency has dampened my learning curve, so to speak.  As far as Unix books
go, that's an excellent suggestion.  I'll pick a couple up some time.
Again, thank you, you and everyone who has responded to my plight ;-)
Take care,

Signature

Isaac Sherman
MotaSoft Software
http://www.motaSoftware.com/
Personal Protection Links:
http://www.safetyAndSecurity.us
http://www.m18.us

Robert D . Sharp - 22 Dec 2004 23:45 GMT
I lurk on this list and I have read every post for years, Isaac, the
recommendation for Unix book(s) is absolutely correct.  Or you could do
a google search on "unix commands" and/or go to a public library and
see what book can get there.

Understanding the background environment is essential to what you want
to do.

> As far as Unix books go, that's an excellent suggestion.  I'll pick a
> couple up some time.
> Again, thank you, you and everyone who has responded to my plight ;-)

--
It has been said before but warrants repeating, "If you think education
is expensive, try ignorance."

Bob Sharp
6th Grade Science Teacher
Board Member, The Learning Space
Past Middle School Representative to the NCCE Board
Recipient of The First Annual Learning Space Achievement Awards for
Members
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.