Conversion of Perl Script to Shell Script..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conversion of Perl Script to Shell Script..
# 8  
Old 12-05-2014
I like the shell; don't get me wrong. But just to keep it interesting...

uname is shell, chomp is perl:
Code:
my $uname = `uname -n`; 
chomp $uname;

The below is not shell. It's a Symantec product about backing up servers.
Code:
`$nbadmin/bpgetconfig -i...`

I wonder how well that would interface with the shell?

...and then there is the arrays and string juggling, which is where perl shines.
# 9  
Old 12-06-2014
Quote:
Originally Posted by ongoto
Hello Corona688

I mentioned security, and what I had in mind at that moment was protection from buffer over-runs, sql-insertions, and the like. The script presented here has the markings of an 'out-facing' app used by...who knows? I just don't think bash would be the best choice out there in the wild wild west. Smilie

System calls are common...bash does it better sometimes (thinking of grep vs Perl grep for example).
Cheers.
a bash programming guru will disagree vehemently with this premise.

there's been very few, if any, situations i've been in that i wasn't able to use bash or awk. perl is a language i will caution people to be very careful with given the simple fact that in most cases, it requires the compilation, download/configuration of modules...which can be detrimental to existing applications on a system.

if perl is your favorite language, fine. stick to it but make sure you know it well enough that you dont have to rely or force your users to have to get modules in order for it to work.

matter of fact, just do a search in this forum alone and you will see very few people care to use perl. its usually awk/bash over perl.
# 10  
Old 12-06-2014
I've turned this thread into a perl vs bash bash haven't I?
Didn't mean to.

Keeping the original poster in mind, whom we haven't heard from since; If someone wants to drop a bash script in his lap, go for it. It isn't going to improve on what he already has IMHO. Rather than leave us arguing about 'what's wrong with perl?', he should be telling us what is wrong with this particular script.

On my own behalf, I have apparently given the impression that I don't like bash. Quite the contrary, bash is what I know best and I use it for everything I do these days. The last time I used perl was to put together a gui app. Looking back I think Python would have been a better choice.
# 11  
Old 12-19-2014
Quote:
Originally Posted by ongoto
I like the shell; don't get me wrong. But just to keep it interesting...

uname is shell, chomp is perl:
uname is not shell! Perl is using a shell here, but it doesn't need to. You should use fork() and exec() to run it more efficiently. But then you would need to set up pipes and such to connect it and worry about closing them after -- all the things BASH does without you even thinking about it. Perl has none of this. It shoves it all into BASH and forgets.

Or you could throw out the perl and not worry about any of it. If you're controlling external processes, you should be using shell, because perl is really bad at it.

( chomp() is not really needed here either. The shell makes do fine without it, but Perl takes things a little too literally. )

Quote:
...and then there is the arrays and string juggling, which is where perl shines.
Perl is terrific at string juggling, but modern shells have arrays. Even better, they have and have always had lists...
This User Gave Thanks to Corona688 For This Post:
# 12  
Old 12-19-2014
Quote:
Originally Posted by ongoto
Keeping the original poster in mind, whom we haven't heard from since; If someone wants to drop a bash script in his lap, go for it. It isn't going to improve on what he already has IMHO.
It is already mostly "bash" code, in a membrane-thin wrapping of perl.

I don't think he's coming back at this point, we wanted him to do too much work.
This User Gave Thanks to Corona688 For This Post:
# 13  
Old 12-19-2014
Hi ongoto...
Quote:
...and then there is the arrays and string juggling, which is where perl shines.
Let me know when PERL, Python or nearly any other language for that matter, can do this:-

Is there anything the shell can't do?

I have made the *NIX shell my language of choice now and all but abandoned Python, I have little experience of PERL however.

EDIT:
BTW, I am looking into FFT stuff for another possible project using the shell...

Last edited by wisecracker; 12-19-2014 at 03:16 PM.. Reason: See above...
This User Gave Thanks to wisecracker For This Post:
# 14  
Old 12-19-2014
Good. We all agree. Smilie

The shell is the coders swiss army knife. But to use it exclusively out of prejudice is cheating yourself. OO languages do have a lot to offer if you need to pass around groups of data all in one go and that sort of thing. The shell now has associative arrays, but they don't stay ordered. Try looping through them. Try passing an array to a function. There goes your indexes. But that doesn't make the shell bad. You're gonna hit a wall in the others too.

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'? On the other hand, Perl lets you do things like "do something unless condition", or "if condition, etc" all in one statement. If Perl can save you some work, then why not use it.? Same with Python and the others mentioned. What would we shell coders do without Awk and Sed and Grep?

Ya got tools that are metric, some are std SAE, and then there are the 'star' bits and the universal sockets. But you can't cut down a tree with a phillips!

Cheers mates Smilie

Quote:
Originally Posted by wisecracker
Hi ongoto...
Let me know when PERL, Python or nearly any other language for that matter, can do this:-

Is there anything the shell can't do?
...
Awesome.
AE6UB said that. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question