Sponsored Content
Top Forums Shell Programming and Scripting Conversion of Perl Script to Shell Script.. Post 302929408 by Corona688 on Saturday 20th of December 2014 11:53:24 PM
Old 12-21-2014
Quote:
Originally Posted by ongoto
In Perl you always end up making calls to the shell because it saves work. Why write a block of Perl code to do 'uname -r'?
You do not "call" a shell.

You must fork a new process, exec it, let it run, wait for it to finish, reap it, and then return to whatever else you were doing. That's what system() does -- just to create a shell. And then the shell, once running, must do so again, to run whatever external command you asked it to do.

So you are running a thing which runs a thing and must wait for it to quit before you can wait for it to quit.

...which it does, having run the single, individual command you fed into backticks or system().

Imagine running full instances of Perl every time you needed to call uname in BASH even though uname has nothing to do with perl. That's the degree of pointless waste that happens when you write external-command-intensive programs in perl. It can be almost cripplingly wasteful.

Just using the shell in the manner it was meant to be used in the first place avoids quite a lot of round trip. Or you could write code in perl to the same effect, except that perl is pretty bad at that...

Quote:
On the other hand, Perl lets you do things like "do something unless condition", or "if condition, etc" all in one statement.
That's a nice feature, isn't it?
Code:
true && echo "this will print"
false && echo "this won't"
true || echo "neither will this"
false || echo "But this will"

sh had it first -- by decades.
Quote:
What would we shell coders do without Awk and Sed and Grep?
You have backpedaled miles from your argument that shell code is somehow "unsafe" while perl code running plethoras of individual short-lived shells is somehow not.

Anyway. Would you agree that running awk thousands of individual times to process tiny amounts of data is a suboptimal use of it?

Perl is good at some things. I enjoy it for some things. Code like the OP is not an effective use of it.

Last edited by Corona688; 12-21-2014 at 01:22 AM..
These 2 Users Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conversion of bash parsing script to perl?

I need help with a perl parsing script. I have some error logs on a windows machine that I need to parse from a text file, but I know nothing about perl. I usually run this bash script on my linux box and it does just what I need. How would I do the same thing with perl and port it to my windows... (2 Replies)
Discussion started by: cstovall
2 Replies

2. Shell Programming and Scripting

Help me with file conversion [Shell Script]

Hello Group, I request your help with a shell script for filter an ascii file (this is small piece of the file): 09/24/2009,00:00,1.0268,1.0268,1.0249,1.0250,518 09/24/2009,01:00,1.0251,1.0261,1.0249,1.0259,424 09/24/2009,02:00,1.0258,1.0272,1.0258,1.0269,372... (3 Replies)
Discussion started by: csierra
3 Replies

3. Shell Programming and Scripting

Encoding conversion in PERL script

I have oracle 9i database installed with UTF-8 Encoding. I want a perl script that converts unicode to utf8 before commiting in database and utf8 to unicode when retreiving from database For example : the word Ïntêrnatïônàlîzâtion has to be stored in database as Internationalization and when retreived... (6 Replies)
Discussion started by: vkca
6 Replies

4. AIX

Need timestamp conversion shell script !!

Can anyone provide me with a ksh or bash script which will accept a timestamp (format is YYYY-MM-DD-HH24.Mi.Ss) and time offset (in hours). The output will be (timestamp passed - time offset passed deducted from it) in the same YYYY-MM-DD-HH24.Mi.Ss format. Basically I am trying to convert the... (1 Reply)
Discussion started by: shibajighosh
1 Replies

5. 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

6. Shell Programming and Scripting

Conversion batch shell script

while converting batch file to shell script ...dis command is ther i dunno how to change...can anyone knws how to change into shell script rm !(D:\temp\XX.txt) (3 Replies)
Discussion started by: monisha
3 Replies

7. Shell Programming and Scripting

Help required for Oracle database shutdown script conversion from shell to perl

Please tell me how to convert below program from shell script to perl. Same commands need to use in shutdown, just need program help for startup. export ORACLE_BASE=/home/oracle1 lsnrctl start lndb1 sqlplus '/ as sysdba' startup; (2 Replies)
Discussion started by: learnbash
2 Replies

8. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

9. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies

10. UNIX for Beginners Questions & Answers

Shell script ouput conversion

Hi All, I am trying to print all the packages info in solaris 11 using below script. #!/usr/bin/env bash pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' > /tmp/cp1 /usr/bin/nawk -F: ' {for (i=1; i<=NF; i++) {gsub (/^ *| *$/, "", $i) ... (5 Replies)
Discussion started by: sravani25
5 Replies
All times are GMT -4. The time now is 11:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy