Fedora Linux Support Community & Resources Center
  #1  
Old 30th March 2007, 11:41 AM
Ullrich Offline
Registered User
 
Join Date: Nov 2006
Posts: 386
Perl

[root@c83-251-158-92 Nissanka]# find / -name perl
/usr/share/doc/bash-3.1/loadables/perl
/usr/share/moin/htdocs/applets/FCKeditor/editor/filemanager/browser/default/connectors/perl
/usr/share/moin/htdocs/applets/FCKeditor/_samples/perl
/usr/bin/perl
[root@c83-251-158-92 Nissanka]#
------------------------------------------------------------
Does the above mean that Perl is installed on my system?
If it is installed, how do i run a simple program? I have never worked with Perl. I know how to work and run HTML and Shell scripts.

I am running FC5. It is a 64bit version.
Reply With Quote
  #2  
Old 30th March 2007, 11:45 AM
pete_1967 Online
Clueless in a Cuckooland
 
Join Date: Mar 2006
Location: Here now, elsewhere tomorrow.
Posts: 3,929
`perl -v` tells you if, and which version, is installed. `which perl` shows you path to perl.
Reply With Quote
  #3  
Old 30th March 2007, 11:49 AM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,076
Quote:
Originally Posted by Ullrich
If it is installed, how do i run a simple program?
http://perldoc.perl.org/perlintro.ht...-Perl-programs
Reply With Quote
  #4  
Old 30th March 2007, 11:58 AM
Ullrich Offline
Registered User
 
Join Date: Nov 2006
Posts: 386
Thanks pete for the reply.
-------------------
[root@c83-251-158-92 Nissanka]# perl -v

This is perl, v5.8.8 built for x86_64-linux-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

[root@c83-251-158-92 Nissanka]#
----------------------------------------------------------------

I just want to run the following program:
-------------------------------------------------
#!/usr/local/bin/perl
#
# Program to do the obvious
#
print 'Hello world.'; # Print a message
------------------------------------------------------------

1. I can write it using the vi editor
2. What should be the end of the name? If it is a scripting programme, I will write 'Trial1' as the name.
Then I would use the command 'chmod 755' to change execution permissions.

3. To run the program, I will write ' ./Trial1 ' and press enter.

4. How do I do it here?
Reply With Quote
  #5  
Old 30th March 2007, 12:07 PM
mmanders Offline
Registered User
 
Join Date: Jan 2007
Posts: 35
Perl files usually have the .pl extension. The extension doesn't really matter. Since you have the #!/usr/local/bin/perl line and you have chmod-ed the file, then ./Trial1 should work. Am I misunderstanding your question?
Reply With Quote
  #6  
Old 30th March 2007, 01:36 PM
pete_1967 Online
Clueless in a Cuckooland
 
Join Date: Mar 2006
Location: Here now, elsewhere tomorrow.
Posts: 3,929
The default interpreter path for perl (and pretty much all others) is '/usr/bin/perl' in Fedora (and RHEL).

To avoid always typing in the whole shebang path, you can use '/usr/bin/env perl' instead (this also allows execution on systems where the path is different).

As mmanders said: perl files usually end in .pl (modules in .pm) and occasionally cgi-scripts are .cgi

Run any perl program, you can always `perl [program_name]`
Reply With Quote
  #7  
Old 30th March 2007, 02:14 PM
mwette Offline
Registered User
 
Join Date: Nov 2005
Location: Los Angeles area
Posts: 887
You had it pretty close. To find path to perl type "which perl".
This should return "/usr/bin/perl". Then your first line should be
#!/usr/bin/perl

Another alternative is to use the "env" command to find perl in your path:
#!/usr/bin/env perl
Reply With Quote
  #8  
Old 30th March 2007, 07:09 PM
Ullrich Offline
Registered User
 
Join Date: Nov 2006
Posts: 386
Thanks everybody for the replies.
I rename the program as '' P1.pl ''.
----------------------------------
#!/usr/local/bin/perl
#
# Program to do the obvious
#
print 'Hello world.'; # Print a message
-----------------------------------------------------------

Then I use the 'chmod 755 P1.pl' to make it executable.
I ran the program by typing 'perl P1.pl' and pressed enter.
The following is the output.

[Nissanka@c83-251-156-176 ~]$ perl P1.pl
Hello world.[Nissanka@c83-251-156-176 ~]$

I hope it is fine. Please tell me if it is flawed.
The reason I gave the name 'P1.pl' is that I would run more similar programs when time permits. I will name them 'P2.pl ' 'P3.pl' , etc.
Reply With Quote
  #9  
Old 30th March 2007, 07:35 PM
pete_1967 Online
Clueless in a Cuckooland
 
Join Date: Mar 2006
Location: Here now, elsewhere tomorrow.
Posts: 3,929
Obviously your script works because you can see the results, however, your shebang line is still wrong and you won't be able to run it unless you use `perl [program_name]` every time,
Quote:
Originally Posted by pete_1967
The default interpreter path for perl (and pretty much all others) is '/usr/bin/perl' in Fedora (and RHEL).

To avoid always typing in the whole shebang path, you can use '/usr/bin/env perl' instead (this also allows execution on systems where the path is different).
Reply With Quote
  #10  
Old 30th March 2007, 08:49 PM
mmanders Offline
Registered User
 
Join Date: Jan 2007
Posts: 35
Indeed - that may be my fault; I think I gave the wrong path in my post. If you modify the 'shebang' line (#!/usr/local/bin/perl) to #!/usr/bin/perl (remove the /local), then you should be able to run your script without explicitly calling the Perl interpreter, i.e. './P1.pl' rather than 'perl P1.pl'. In fact, although .pl is a conventional extension, the shebang line means you don't *need* to use the extension at all.

Best of luck!
Reply With Quote
  #11  
Old 31st March 2007, 01:14 AM
mwette Offline
Registered User
 
Join Date: Nov 2005
Location: Los Angeles area
Posts: 887
My only suggestion: change
print 'Hello world.';
to
print 'Hello world.\n';
Reply With Quote
  #12  
Old 13th October 2012, 06:32 AM
kevin tough Offline
Registered User
 
Join Date: May 2006
Posts: 115
linuxfirefox
Re: Perl

I just went through installing Perl on Fedora 17 and getting to the point I can start effectively using it. Here are the steps I went through. From a console as root run this command.
Code:
# yum install perl perl-Pod-Perldoc
This command will check that you have perl and it's standard documentation installed. To learn about perldoc type in "perldoc intro".. The command "perldoc perldoc" will explain the usage of perldoc.
Next create a simple program to try out perl. Create thiis file named "HelloMe" with your editor of choice and save it in a directory such as /home/<your name>/Code/Perl/Sandbox.
Code:
#!/usr/bin/perl
use warnings;

print "Enter your name:\n";
$name = <STDIN>;
chomp($name);

print "Hello $name!\n";
With your console open in this directory change the file type to an executable with
Code:
$ chmod +x HelloMe
Now if you type "perl HelloMe" the script will execute. In order to be able to just type the name of the script you need to setup bash to search this directory. This is done by adding two lines to the file .baschrc found in your home directory. The default .bashrc file will look like this if you should chose your Sandbox directory such as I have.
Code:
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# User specific aliases and functions
PATH=$PATH:$HOME/Code/Perl/Sandbox
export PATH
Reply With Quote
Reply

Tags
perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl modules install help for Perl n00b notmyrealemail Using Fedora 0 22nd July 2006 12:22 AM
Perl error? when testing Perl installation magnublm Using Fedora 3 21st September 2005 10:21 PM
Any way to resolve x86_64 Perl issue without yum remove perl.i386? jert Using Fedora 3 24th July 2005 07:31 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Using Fedora 0 16th December 2004 11:42 PM


Current GMT-time: 09:17 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat