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..
# 22  
Old 12-22-2014
@ Corona688

I see. Well then, this is me, back pedaling. I have no doubt what you are saying is accurate. And from that I gather that Perl is running on top of the shell rather than independent of it. That I didn't realize.

It follows that 'system' in Perl is an alias for 'shell' then, to put it in simple terms. That being the case demonstrates a LOT of overhead that I wasn't aware of. Thanks for enlightening me.

So when writing scripts to manage local stuff, use the shell. I'm good with that.

I'm wondering now if the same is true for Python?
# 23  
Old 12-22-2014
Quote:
Originally Posted by ongoto
@ Corona688

I see. Well then, this is me, back pedaling. I have no doubt what you are saying is accurate. And from that I gather that Perl is running on top of the shell rather than independent of it. That I didn't realize.
Oh, it is independent of it.

system() is not. system() means "run this command in a shell". it kind has to use a shell, because that's what it means.

So, to run external commands, it generally has to use a shell.

Perl built-ins and perl modules, on the other hand, are native. (Unless they use system() for something.)
Quote:
I'm wondering now if the same is true for Python?
Quite probably. Remember, that's what system() means -- "run this command in a native shell".

Also remember that not using a shell to handle it means you have to handle splitting, pipes, and path lookups yourself. That's all the shell's job traditionally. So it's either do all the hard work yourself, build at least half of a good shell into your language, or hand the job off to the shell.

As for python's overhead in general, one might wonder, how many files does it take to do absolutely nothing? The answer is interesting:

Code:
~ $ strace bash /dev/null 2>&1 | grep -c open
8
~ $ strace perl /dev/null 2>&1 | grep -c open
8
~ $ strace awk '{}' /dev/null 2>&1 | grep -c open
5
~ $ strace python /dev/null 2>&1 | grep -c open
53
~ $

# 24  
Old 12-22-2014
Perl stands for Practical Extraction and Report Language. It would logically be the best choice for that purpose. It falls down when it comes to external commands.
Bash is right at home in that respect.

RE: the numbers
My everyday OS is Centos6. Because it sports Gnome2, library and software versions have to be kept back for compatability reasons, which might explain the differences here.

Yes, these numbers are interesting. I guess they represent processes?
Code:
strace python /dev/null 2>&1 | grep -c open
174
strace perl /dev/null 2>&1 | grep -c open
31
strace awk '{}' /dev/null 2>&1 | grep -c open
7
strace bash /dev/null 2>&1 | grep -c open
9

Could it be that Python and Perl are compiled? and bash is not? I dunno.

Edit:
A little off topic, but you mentioned doing the shell's work one's self. There's a module for Perl...
Zoidberg - a modular perl shell | SourceForge.net
Just an FYI I forgot to mention.

Last edited by ongoto; 12-22-2014 at 04:17 AM.. Reason: P.S.
# 25  
Old 12-23-2014
Quote:
Originally Posted by ongoto
Yes, these numbers are interesting. I guess they represent processes?
No. They are exactly what I said -- the number of files they open to do exactly nothing.
Quote:
Could it be that Python and Perl are compiled? and bash is not?
No. They are all compiled.
# 26  
Old 12-24-2014
Quote:
Originally Posted by ongoto
Perl stands for Practical Extraction and Report Language. It would logically be the best choice for that purpose. It falls down when it comes to external commands.
Bash is right at home in that respect.
While it may be a different (or more difficult) than bash, with respects, perl does not "fall down" when it comes to external commands. It just depends on what you are trying to accomplish.
# 27  
Old 12-24-2014
Back in the day, Mandrake (now Mandriva) chose Perl as the language to write all their system configuration tools with. They even wrote console counterparts to their tools integrating ncurses with Perl. It became one of the easiest to use and most popular of all Linux distros. Mageia and PCLinuxOS still use Mandriva as a base for their own respective distros because those tools are so good. Those distros are prolly the best resources for anyone wanting to learn Perl and is looking for Perl source examples to study. The Linux game 'Frozen Bubbles' is written also with Perl. Lots of graphics and animation. Perl is not the dog to throw rocks at.

Compared to small bash scripts and one-liners you could say Perl 'falls down' because it gobbles resourses. It's argued that it's not the best choice in that arena, and I agree. Shell scripts do have their place. But when it comes to gathering and reporting data, which is what the script in the first post is all about, or interfacing with humans, like the examples given above, I argue that Perl does it better (and faster) than any shell script could, at least any that I've ever seen.

P.S.
With respect to the shell's versatility, notice that Chubler_XL took the time and went to the trouble of converting the OPs script (post #19). Good job Chubler_XL. Whether it will handle just about any kind of data you throw at it remains to be seen.

Cheers

Last edited by ongoto; 12-25-2014 at 12:50 AM.. Reason: P.S.
# 28  
Old 01-05-2015
Quote:
Originally Posted by ongoto
The Linux game 'Frozen Bubbles' is written also with Perl. Lots of graphics and animation. Perl is not the dog to throw rocks at.
It uses several award-winning C libraries to do so, which work equally well in C, Perl, Python, Ruby, or dozens of other languages. Shell, admittedly, is not one of them.

Strip perl of its modules, and it's way worse at I/O than shell.
Quote:
But when it comes to gathering and reporting data, which is what the script in the first post is all about, or interfacing with humans, like the examples given above, I argue that Perl does it better (and faster) than any shell script could, at least any that I've ever seen.
I don't think you know a lot about shell or perl, really. But we've gotten off topic.

My points:

1) It's possible to write bad code in any language.
2) Bad perl code is not better than good shell code.

Therefore:

Perl code is not automatically better than shell code, even for tasks you consider it "ideal" for.

(This is not one of them, for reasons I've spent the last several pages explaining repeatedly.)

Quote:
Whether it will handle just about any kind of data you throw at it remains to be seen.
I thought you gave up that argument pages ago.

If you have any specific concerns about his program, please name them and we will happily correct any errors. Otherwise please stop your baseless fearmongering. That you don't know the potholes to avoid doesn't mean we don't.

Blocking injection, and handling error conditions in general, has always been the programmer's responsibility. If you think you can't exploit a perl script, you need to learn a lot more about programming in general.

Last edited by Corona688; 01-05-2015 at 06:16 PM..
This User Gave Thanks to Corona688 For This Post:
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