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 / July 2004



Tip: Looking for answers? Try searching our database.

Incorrect Path or format?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick Pappas - 27 Jul 2004 14:16 GMT
I am just learning to use Perl on OS 10.3. I am not an experienced
Unix programmer, so I am probably doing something very basically
wrong.

My first "Hello World" script is not executing. I created a Plain
Text script using TextEdit and saved it in my Documents folder with
the name "simple_print".

In Terminal, I give a pwd command and get back the reply: /Users/username

When I type: perl /Documents/simple_print, I get the diagnostic
Can't open perl script "/Documents/simple_print": No such file or directory

That seems to mean I am making some kind of mistake with the path name.

The first line in the program is: #!  /usr/bin/perl

What is wrong?

Nick
Adam Witney - 27 Jul 2004 14:21 GMT
Hi Nick,

You are trying to run a file from the Document folder on your hard disk, not
your home directory... You need to do it like this

perl ~/Documents/simple_print

Or

perl /Users/username/Documents/simple_print

But I suspect you will also need to make the file executable first, with
this command

chmod a+x  ~/Documents/simple_print

Cheers

adam

> I am just learning to use Perl on OS 10.3. I am not an experienced
> Unix programmer, so I am probably doing something very basically
[quoted text clipped - 16 lines]
>
> Nick

Signature

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Andrew Mellinger - 27 Jul 2004 14:36 GMT
To clarify what Adam is saying (I didn't understand his answer at first.)
Yes, you are in the correct place (your home directory) but when you
typed

/Documents/simple_print

that is a full-path.  To execute using a relative path from within your
user's directory (which pwd showed you that youy were) you could use
either:

Documents/simple_print

-or-

./Documents/simple_print

Notice that neither is prepended with a slash which indicates full path.
Adams answer of using the ~ expansion works just as well.

-Andrew

> Date: Tue, 27 Jul 2004 14:21:37 +0100
> From: Adam Witney <awitney@sghms.ac.uk>
[quoted text clipped - 46 lines]
> dangerous content by MailScanner, and is
> believed to be clean.
Jeff Lowrey - 27 Jul 2004 14:24 GMT
>I am just learning to use Perl on OS 10.3. I am not an experienced Unix
>programmer, so I am probably doing something very basically wrong.

You'll get there.

>My first "Hello World" script is not executing. I created a Plain Text
>script using TextEdit and saved it in my Documents folder with the name
>"simple_print".
>
>In Terminal, I give a pwd command and get back the reply: /Users/username

This is telling you that the full path to your Documents folder is actually
/Users/username/Documents.

>When I type: perl /Documents/simple_print, I get the diagnostic
>Can't open perl script "/Documents/simple_print": No such file or directory

Unix paths are constructed starting from a root directory.  The name of
that root directory is "/".

If you want to use a relative path, that is one that does not start from
"/", you need to indicate that you are building a relative path.   This is
done with one of a few different characters - either ".", or "~"
usually.  "~" means "Relative to my home directory", and "." means
"relative to the current directory.

So you could cd to /, and then "perl ~/Documents/simple_print", and that
would be the same as "perl /Users/username/Documents/simple_print".   Or
you could cd (or not, since you're starting there) to /Users/username, and
say "perl ./Documents/simple_print".  (notice the period before the first
slash), and that would also be equivalent to "perl
/Users/username/Documents/simple_print".

But if you were cded to somewhere else like '/etc/mail', then "perl
./Documents/simple_print" would be equivalent to "perl
/etc/mail/Documents/simple_print" where "perl ~/Documents/simple_print"
will always be equivalent to "perl /Users/username/Documents/simple_print".

-jeff lowrey
who probably is not the first or only person to answer this, and his
message will likely show up late
Doug McNutt - 27 Jul 2004 14:51 GMT
>When I type: perl /Documents/simple_print, I get the diagnostic
>Can't open perl script "/Documents/simple_print": No such file or directory

Your documents folder is probably in your home directory rather than on the root.

perl $HOME/Documents/simple_print

or

cd $HOME/Documents
perl simple_print

The OS neXt GUI confuses the concept when it offers the option of saving to "Documents".

Signature

Applescript syntax is like English spelling:
Roughly, but not thoroughly, thought through.

Nick Pappas - 27 Jul 2004 15:06 GMT
Thanks for the responses - so many and so quickly.

I'm sure I'll be back with more. I am working my way up to writing a
program that will read and store temperature information from some
external sensors.

Nick

>I am just learning to use Perl on OS 10.3. I am not an experienced
>Unix programmer, so I am probably doing something very basically
[quoted text clipped - 16 lines]
>
>Nick
Chris Devers - 27 Jul 2004 15:17 GMT
> Thanks for the responses - so many and so quickly.

The easy questions tend to get more responses :-)

> I'm sure I'll be back with more. I am working my way up to writing a
> program that will read and store temperature information from some
> external sensors.

Unless what you're doing is OSX specific -- which would be cool, as the
project sounds interesting, but my guess is that it's more generic than
that -- then the Perl Beginners list might be the right place for this.

Basic information on the list is available at <http://learn.perl.org/>;
there's a subscription box on the top-right side of the page. There's
also a FAQ for the list at <http://learn.perl.org/beginners-faq>.

Good luck with your project :-)

Signature

Chris Devers

Nick Pappas - 27 Jul 2004 15:36 GMT
>Unless what you're doing is OSX specific -- which would be cool, as
>the project sounds interesting, but my guess is that it's more
>generic than that -- then the Perl Beginners list might be the right
>place for this.

Yes, I'll be there as well, I just felt this question might be
tangled up in OS X and I would get a more helpful response here.

The application is OS X based.
 
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.