LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2005, 11:50 AM   #1
meadensi
LQ Newbie
 
Registered: Feb 2005
Posts: 18

Rep: Reputation: 0
Really lame Perl question


Guys,

I am SO embarrased by this. I can't get my hello world Perl program to work (oh the shame of it). Here it is

firstperl:

#!/usr/bin/perl
#
# Program to do the obvious
#
print 'Hello world.'; # Print a message

I've done a chmod +x firstperl. I also had to take out 'local' from the shebang first line. I get the error

bash : print : command not found

which kinda tells me Fedora Core 3 still thinks its a bash script.

How do I get it to recognize it as a perl program.

Sorry to be so lame, thanks

Meadensi
 
Old 06-22-2005, 12:21 PM   #2
mmmm
Member
 
Registered: Oct 2004
Location: Poland
Distribution: Slack 10.1, Mandrake 10.1
Posts: 118

Rep: Reputation: 15
are you sure perl is in /usr/bin ? type `which perl` to check it. When I run it, it works... Try to run :
Code:
# perl firstperl
Maybe it will run ?
 
Old 06-22-2005, 12:40 PM   #3
meadensi
LQ Newbie
 
Registered: Feb 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Ok, enough to get going for now

Thanks mmmmm,

perl firstperl works and this is enough to get me going so I can continue with Perl tutorial.

However when I did

which perl

I got

/usr/bin/perl

Thanks anyway.

Meadensi
 
Old 06-22-2005, 04:18 PM   #4
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Thats messed up, try doing this:

/usr/bin/perl yourscriptname


There shouldn't be a difference between that, and simply doing a

./yourscriptname


But at least you can run scripts and learn how to write Perl, I still think its pretty weird though.
 
Old 06-22-2005, 06:52 PM   #5
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
you don't by chance have a blank line or space before the #!, do you?
 
Old 06-22-2005, 07:14 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Perhaps it's a DOS text file.

If you run "perl mydosfile.pl", the Perl will happily ignore the CR/LF's, and it will work.

If you run "./mydosfile.pl", however, the shell will see "#!/usr/bin/perl" and try to execute something it thinks is "/usr/bin/perl^M". And barf.

Please try this:

a) vi -b myfile.pl
<= DO A "BINARY EDIT" OF YOUR "HELLO PERL" TEXT FILE

b) Delete any/all "^M" (DOS CR/LF end-of-line characters) you find

c) Save and try "./myfile.pl" again
 
Old 06-22-2005, 07:50 PM   #7
meadensi
LQ Newbie
 
Registered: Feb 2005
Posts: 18

Original Poster
Rep: Reputation: 0
My mishtake

This is my mistake. As with bash scripts I need to use the period. DOH!

Just for the record ./firstperl works as does
/usr/bin/perl firstperl

Also for the record it was created originally in vi (not a DOS file) and there were no blanks spaces or blank top lines.

The limitation is the same as for bash scripts. On my machine I have to do

bash mybashscript or ./mybashscript

I cannot just do
mybashscript despite the she-bang top line declaring it to run under bash. I think I read somewhere that its is some sort of security restriction.

I suppose I should not expect any different for perl scripts.

To continue I will use either

perl myperlscript or ./myperlscript

Thanks for all your efforts guys I appreciate it, another vodka and tonic for me ....
Meadensi
 
Old 06-23-2005, 01:51 AM   #8
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Your script is not in your PATH, so you can not execute it
with simply typing its name, you have to give the full path
like /path/to/myperlscript or ./myperlscript (if myperlscript
is in the current directory)

For my part, I created a bin directory in my $HOME and
added it to my PATH in my ~/.bashrc file :
Code:
export PATH=$HOME/bin:$PATH
So I simply put all my scripts here and I can execute them
with their name at command line (without the period or
the full path)

Last edited by keefaz; 06-23-2005 at 01:52 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Totally lame question :-) Focalpoint Linux - Newbie 12 07-05-2004 06:10 AM
Lame KDE Question... cclavey Linux - Software 8 04-23-2003 02:20 PM
really lame question cclavey Slackware 3 04-07-2003 05:21 PM
Really Lame Question cclavey Linux - Software 5 03-30-2003 07:59 PM
Really Lame Timezone question Supp0rtLinux Linux - General 0 04-08-2002 11:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration