Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-13-2010
Registered User
 

Join Date: Feb 2010
Location: USA
Posts: 65
Thanks: 1
Thanked 0 Times in 0 Posts
Perl file

Hi,
Can someone please tell me how to run a perl file in unix.
for instance, I have one file or perl script saved as perl.pl and i have one text file and i want to run .pl file on .txt file.what should i do?

Thanks
Sponsored Links
    #2  
Old 03-13-2010
durden_tyler's Avatar
Registered User
 

Join Date: Apr 2009
Posts: 1,684
Thanks: 4
Thanked 209 Times in 189 Posts
Quote:
Originally Posted by Learnerabc View Post
...
Can someone please tell me how to run a perl file in unix.
You feed your Perl script to the "perl" interpreter in order to run it.


Code:
perl myfile.pl

where myfile.pl is your text file that contains Perl code.

Alternatively, if your Perl script has the shebang in the first line -


Code:
#!<path_to_perl_on_your_system>

and you have executable permission on your script, then you can simply invoke your script as -


Code:
myfile.pl

or

./myfile.pl

depending on whether or not you have the current directory (".") in your PATH variable.

Quote:
...
for instance, I have one file or perl script saved as perl.pl and i have one text file and i want to run .pl file on .txt file.what should i do?
...
I'll assume "to run .pl file on .txt file" means that you want your Perl script to process your text file.
Quite simply, you'd code something like this -


Code:
open (IN, "myfile.txt") or die "Can't open myfile.txt: $!";
while (<IN>) {
  # do whatever you want to do with the current record
  # the "while" loop iterates through one record at a time
}
# good practice to clean up after you're done
close (IN) or die "Can't close myfile.txt: $!";

HTH,
tyler_durden
Sponsored Links
    #3  
Old 03-15-2010
thillai_selvan's Avatar
Registered User
 

Join Date: Feb 2010
Location: Chennai
Posts: 190
Thanks: 0
Thanked 1 Time in 1 Post
You can also run perl's one liner script using perl command with -e option
Example:


Code:
perl -e 'print "hello world\n"'

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract string from a file & write to a new file (Perl) LuckyGuy Shell Programming and Scripting 3 11-18-2009 09:43 AM
Perl : Process a file in perl deo_kaustubh Shell Programming and Scripting 4 09-29-2009 08:44 AM
perl -write values in a file to @array in perl meghana Shell Programming and Scripting 27 06-07-2009 05:05 PM
PERL:How to convert numeric values txt file to PACKED DECIMAL File? aloktiwary Shell Programming and Scripting 1 05-20-2009 09:55 AM
Convert XML file into TEXT file using PERL seript Rudro Shell Programming and Scripting 0 06-11-2008 10:03 AM



All times are GMT -4. The time now is 03:45 AM.