Perl file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl file
# 1  
Old 03-13-2010
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
# 2  
Old 03-13-2010
Quote:
Originally Posted by Learnerabc
...
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
# 3  
Old 03-15-2010
You can also run perl's one liner script using perl command with -e option
Example:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

3. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies

4. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

5. Programming

Perl- How to catch the file in perl code?

Hi, plz see the below code , i have catch the file "Orders.20110714.out "file as a Orders*.out. but it giving me an error .it does not open the file. if the same thing i have done by code code-> ls Orders*.out then it gives me the output Orders.20110714.out i am trying apply the... (1 Reply)
Discussion started by: pspriyanka
1 Replies

6. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

7. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

8. Shell Programming and Scripting

Perl : Process a file in perl

I have a file with following data : Qspace: COLOR: Queue: doColor Qspace: COLOR: Queue order: fifo Qspace: COLOR: Out of order: none Qspace: COLOR: Retries: 5 Qspace: COLOR: Queue: setColor Qspace: COLOR: Queue order: fifo Qspace: COLOR: Out of order: none Qspace: COLOR: Retries: 5... (4 Replies)
Discussion started by: deo_kaustubh
4 Replies

9. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

10. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies
Login or Register to Ask a Question