Visit Our UNIX and Linux User Community


perl limitations vs. bash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl limitations vs. bash?
# 1  
Old 05-12-2010
perl limitations vs. bash?

I've building a bunch of bash scripts, and am thinking about "converting" to perl, and have a couple questions first:

1. Is there anything bash will do that perl won't?
2. How steep is the learning curve?
3. If perl's more powerful, why?
4. I've built a small app in python, which seemed nice, isn't there a wider support depth (i.e. example code, # of users)in perl than python?
5. I'm building mostly sysadmin scripts, if I were going to do more web integration (think php/javascript) with my code, would perl or python be easier to build, and which would be more powerful, or are they roughly the same?

This isn't meant to be a troll, I really would like to continue learning, and you guys have been very helpful learning bash, awk, sed, grep, etc. on multiple occasions Smilie
# 2  
Old 05-12-2010
Quote:
Originally Posted by unclecameron
I've building a bunch of bash scripts, and am thinking about "converting" to perl, and have a couple questions first:

1. Is there anything bash will do that perl won't?
Not really. perl's a more "complete" language. bash is better oriented to scripts.
Quote:
2. How steep is the learning curve?
Almost vertical.
Quote:
3. If perl's more powerful, why?
It's a lot more extensible and supports complex data structures.
Quote:
4. I've built a small app in python, which seemed nice, isn't there a wider support depth (i.e. example code, # of users)in perl than python?
Perl support seems to be spotty, either very good or very bad. It may be I just never found the right place.
Quote:
5. I'm building mostly sysadmin scripts, if I were going to do more web integration (think php/javascript) with my code, would perl or python be easier to build, and which would be more powerful, or are they roughly the same?
Code:
$ strace bash 2> bash-log
^C
$ strace perl 2> perl-log
^C
$ strace python 2> python-log
^C
$ grep '^open' python-log | wc
    149    1172   13744
tyler@mecgentoo ~ $ grep '^open' perl-log | wc
      9      36     399
tyler@mecgentoo ~ $ grep '^open' bash-log | wc
      7      28     323
tyler@mecgentoo ~ $

Python tries openening 149 files to do nothing at all. For scripts that run once and terminate, python's an absolute pig. For things that stick around, that's tolerable.
# 3  
Old 05-12-2010
Bash, Perl, Python

I cannot compare Python, as I do not use snakes here. ;-)

Bash is easy and (in version 4) remarkably complete for a shell. Shell scripting starts with automating exactly what you would do on the command-line, so testing is easy. Scripting in a shell usually requires calling external utilities as tools to complete what that shell cannot. My BASH scripts often call ls, rm, grep, find, mv, awk, tr, sed, or other tools.

Perl is far more complete. The syntax is different, and less likely to match what you would do on the command-line. One of its great advantages is that every tool you would call in a script is either built into the Perl interpreter, or is a function that is simple to recreate in Perl. The result is that your Perl script only acts on data, and does not have to call external tools.

I enjoy scripting many things in Bash: in particular scripts that start, stop, or signal services. Since these scripts deal with external services, there is no advantage in using Perl. When I automate something that has only to act and can act faster if external calls are eliminated, I use Perl.

I recommend both, and have never run into a support problem with either. The learning curve is TERRIBLY steep if you feel you have to MASTER perl, because there is a LOT of it! If you only need enough to solve problems in a better, more efficient manner than you can with BASH, then the learning curve is irrelevant: just learn enough to do the job. After using Perl for a few jobs you will find yourself feeling and performing like an expert.

Once you begin learn perl, you will find yourself coding awk, sed, and tr filters far less often. You will even call Perl one-liners from your Bash scripts because they will seem faster and easier to implement.

No language or tool is a total answer to all problems, but the common description of Perl is the "Swiss Army Chainsaw": it cuts all of your problems down to size. You WANT it in your toolbox, you just do not know yet how much.
# 4  
Old 05-12-2010
Use Perl;

Quote:
Originally Posted by unclecameron

1. Is there anything bash will do that perl won't?
Perl can do everything BASH can do a lot faster. Perl can also do many things which BASH cannot, e.g. connect to a legion of RDBMS implementations seemlessly with DBI, and support full OO application development.

Quote:
Originally Posted by unclecameron

2. How steep is the learning curve?
Many feel it is quite sharp. This is a good place to start: Amazon.com: Learning Perl, 5th Edition (9780596520106): Randal Schwartz, Tom Phoenix, brian d foy: Books


Quote:
Originally Posted by unclecameron

3. If perl's more powerful, why?
1. Perl's has stronger standard data types, excellent support for references and complex data structures, a rich set of built-in functions and superb support for regular expressions.

2. Perl is much faster than BASH ( but then, so is almost everything else. Time how long it takes both to count to 500,000,000, or to compute a factorial ).

3. Perl has unparalleled 3rd party support with external libraries available from CPAN ( the Comprehensive Perl Archive Network ). For Instance, want to encrypt something with the Whirlpool algorithm? Just use Digest::Whirlpool right out of the box. You would not be so lucky in BASH, Python, or PHP. i.e. you'd be implementing the algorithm on your own.

There are 115 modules in the Digest:: space and 409 modules in Crypt:: compare that to PHP PEAR for instance. It's not even close.

Quote:
Originally Posted by unclecameron

4. I've built a small app in python, which seemed nice, isn't there a wider support depth (i.e. example code, # of users)in perl than python?
Compare CPAN to Python's Python Package Index : PyPI and you are likely to find CPAN superior. Python really does not have a community-accepted one-stop-shop for all serious 3rd-Party Modules. PHP Pear is much more serious, but it still fails in comparison to CPAN. Knowledge of the pre-existing code on CPAN can make writting applications in Perl Geometrically faster, even without a framework.

Frameworks are where Perl has been weak ( compare, Python Django, Ruby on Rails, or PHP Zend ), until the advent of Catalyst which is a fully featured Perl MVC framework which is catching on very rapidly.

Combine CPAN and Catalyst, and you are really cooking with propane.

Quote:
Originally Posted by unclecameron

5. I'm building mostly sysadmin scripts, if I were going to do more web integration (think php/javascript) with my code, would perl or python be easier to build, and which would be more powerful, or are they roughly the same?
Don't build sysadmin scripts in Python or PHP. Use Perl, BASH, awk, sed for those things.

For the Web PHP, Perl, and Python all have strengths and weakness. You could write a thesis on this topic and some do. I'll avoid that.

Summary: despite taking a lot of mostly undeserved guff, Perl remains an excellent choice for everything from one-line one-shot filesystem transforms to full-fledged MVC OO Web Applications.

If you can handle a steep learning curve and *symbolism*, e.g. $# instead of LAST_ELEMENT_IN_THE_ARRAY, Perl will serve you well for many years to come.

Hope That Helps.

Last edited by deindorfer; 05-12-2010 at 07:47 PM.. Reason: Removed Duplication
These 2 Users Gave Thanks to deindorfer For This Post:
# 5  
Old 05-12-2010
Learning Curve

A steep learning curve means that more information can be learned over a short time. Most people believe, mistakenly, that a steep learning curve is bad. This probably comes from believing they have to climb it rather than it being a graph of knowledge vs time.

Perl does not have a steep learning curve, i.e. It will take you longer to learn than Bash. Perl has more features, five ways to solve any problem, and CPAN.org which has a module for almost anything you can think of.

Perl is well worth learning as it is a very powerful and flexible language. This is in spite of its NON-steep learning curve.
# 6  
Old 05-13-2010
Steep Learning Curve: Meaning

Quote:
Originally Posted by m1xram
. Most people believe, mistakenly, that a steep learning curve is bad.
Please See here, m1xram:

Learning curve - Wikipedia, the free encyclopedia

In particular this:

Quote:

Over time, however, the metaphor has become more commonly used to focus on the pattern's negative aspect, namely the difficulty of learning once one gets beyond the basics of a subject.
Spot on on Perl Smilie
# 7  
Old 05-13-2010
Wikipedia [needs citation]

lol, Wikipedia. It "needs citation" because it is wrong. Would you prefer to learn less over a greater time, with a NON-steep learning curve?

Image

The steeper the curve the more knowledge you get in less time. As the slope approaches infinity you instantaneously know more. Think Matrix upload to your brain.

I wish people would stop using this term, it's embarrassing.

Previous Thread | Next Thread
Test Your Knowledge in Computers #438
Difficulty: Medium
TypeScript is a free and open-source subset of JavaScript developed by Microsoft.
True or False?

10 More Discussions You Might Find Interesting

1. Linux

Linux partitions and limitations

In recently reading an article on linux basics before I embark and my personal installation project I came across this passage - IDE drives have three types of partition: primary, logical, and extended. The partition table is located in the master boot record (MBR) of a disk. The MBR is the... (12 Replies)
Discussion started by: Synchlavier
12 Replies

2. Solaris

Solaris limitations

Hi, I recently started working with Solaris, and what I noticed is that a lot of commands I used to regularly use don't work, like sed -i and grep -r. I have found work arounds for these problems though but it's a pain in the ass. I'm just wondering why they decided not to include these handy... (4 Replies)
Discussion started by: Subbeh
4 Replies

3. Red Hat

Eth0 Limitations

Hi, I have noticed some performance issues on my RHEL5 server but the memory and CPU utilization on the box is fine. I have a 1G full duplexed eth0 card and I am suspicious that this may be causing the problem. My eth0 settings are as follows: Settings for eth0: Supported ports: ... (12 Replies)
Discussion started by: Duffs22
12 Replies

4. UNIX and Linux Applications

gnuplot limitations

I'm running a simulation (programmed in C) which makes calls to gnuplot periodically to plot data I have stored. First I open a pipe to gnuplot and set it to multiplot: FILE * pipe = popen("gnuplot", "w"); fprintf(pipe, "set multiplot\n"); fflush(pipe); (this pipe stays open until the... (0 Replies)
Discussion started by: sedavidw
0 Replies

5. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

6. UNIX for Dummies Questions & Answers

Password limitations.

I would like to set my minimum password length to on Linux and AIX. However, doing this normally would only make it so newly added users will be affected by this. I would like for when I make this change, it either truncates everyone elses password, or prompts them to change it to 8+ characters.... (2 Replies)
Discussion started by: syndex
2 Replies

7. UNIX for Dummies Questions & Answers

csplit limitations

I am trying to use the csplit file on a file that contains records that have more than 2048 characters on a line. The resultant split file seems to ignore the rest of the line and I lose the data. Is there any way that csplit can handle record lengths greater than 2048? Thanks (0 Replies)
Discussion started by: ravagga
0 Replies

8. AIX

SORT Command Limitations

Hi every body, On AIX 4.3.3 what is the maximum file size that can be used with sort command? (0 Replies)
Discussion started by: aldowsary
0 Replies

9. UNIX for Dummies Questions & Answers

Unix Sort - Limitations

Hi All, I want to sort a flat file which will contain millions of records based on a key/field. For this I want to use unix sort command and before that I want to make sure that unix sort command has any file size limitations. And also please let me know whether I have to change any... (2 Replies)
Discussion started by: chprvkmr
2 Replies

10. UNIX for Dummies Questions & Answers

mkdir limitations

What characters can't be used with a mkdir? Any limits on length of name? Thank you, Randy M. Zeitman http://www.StoneRoseDesign.com (12 Replies)
Discussion started by: flignar
12 Replies

Featured Tech Videos