Using UNIX command in perl script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using UNIX command in perl script.
# 1  
Old 01-15-2013
Using UNIX command in perl script.

I wish to know if there is any limitation in using unix commands in perl script or it is just we should avoid using them in our perl script.

For e.g Below is the command to get the recent file in a dir.:
Code:
$lcsvFile = `cd "$l_inputfilepath";ls -1t *.CSV|tail -1`

Is there any harm in coding as done above ?

Last edited by Scott; 01-15-2013 at 04:01 PM.. Reason: ICODE tags for CODE tags
# 2  
Old 01-15-2013
No it not harmful per se. But if your perl is nothing but shell commands then your code belongs in a shell script.

Sometimes writing the perl equivalent to a simple shell command is not worth it, unless you want performance. Performance meaning the command is inside a loop that executes 10000 times. Once or twice is perfectly fine and has an almost imperceptible effect on performance. 100's of shell calls - no way....

What you are probably doing is using an efficient shell builtin - ls - and other than creating child processes is way more efficient the opendir(), readir(), etc. in perl - because those system API's are buried inside perl pm's. And perl is interpreted.
This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] UNIX command in PERL

I tried to use this command in PERL code. when I run this on shell , it's working fine. grep -v "^#" /oratab | awk -F: '$1 == "'$server'" {print $2}' inside PERL $ohome = `grep -v "^#" /oratab | awk -F: '$1 == "'$server'" {print $2}'` ; but, it's not returning anything back ... what... (0 Replies)
Discussion started by: talashil
0 Replies

2. UNIX for Dummies Questions & Answers

PERL/UNIX - SVN check in command

I am working in perl. I need to do some svn check in from my server. I need to install svn in my server. I have the package "svn" in my server path How can I install that in my server. I tried , but this doesnt work. Can you please help with the command to be used. Thanks in... (0 Replies)
Discussion started by: irudayaraj
0 Replies

3. Shell Programming and Scripting

Cannot execute Unix command in a simple perl script

Am trying to lean perl scripting in Unix OS to automate my tasks. Please find the below perl script i have tried #!/usr/bin/perl -w print "Please Enter the VG name to be checked:"; $A = <>; print "Please Enter the free size to be checked in GB:"; $B = <>; $vgcheck = `vgdisplay... (7 Replies)
Discussion started by: jayachandran87
7 Replies

4. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

5. Shell Programming and Scripting

How do I launch a command on an existing terminal in unix using PERL

Hello, I have a PERL-TK based GUI from which I want to launch a command on an existing UNIX terminal (this is also the parent terminal for this perl based gui window). The command I want to launch is interactive (there is no intention to interact with that command from the same PERL gui i.e. no... (2 Replies)
Discussion started by: AnuragJindal
2 Replies

6. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

7. Shell Programming and Scripting

ftp from windows to unix using a perl script on unix machine

i need to ftp a file from windows to a unix machine by executing a sript(perl/shell/php) from that unix machine.i can also use HTML and javascript to build forms. (3 Replies)
Discussion started by: raksha.s
3 Replies

8. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

9. Shell Programming and Scripting

Unix command in Perl

Hi, I have a perl script. It needs to open a file but the file that it will open will depend on the result of a unix command "tail -1". How can I do that in perl, to open a file which is the results from a unix command? Thanks in advance! Hope you can help me. (2 Replies)
Discussion started by: ayhanne
2 Replies

10. Shell Programming and Scripting

E-Mail from command line for UNIX and Perl??

Hi Is there any way to use UNIX and Perl to automate sending e-mail. I got a dynamic changing file that send out to people in my mailing list and want to experinment to see if Perl and UNIX can send it out for me when the content is change. I found a Perl source code but dont really know how to... (4 Replies)
Discussion started by: jy2728
4 Replies
Login or Register to Ask a Question