Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl vs. shell script 2

Status
Not open for further replies.

spyghost

Technical User
Jan 17, 2003
52
HK
hi,

when would you use perl script to do a task, and when would you use a shell script to do a task?
 
depends on the task spyghost - if you look at something and a Perl solution occurs to you, use Perl - if you look at something and a shell solution occurs to you, use the shell. Unless an AWK solution comes to mind of course, you should use Perl then :)

Mike

shows ways to help with Tsunami Relief.

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Oh Mike,

That's just bringin' the wraiths man ... ;-)

--Paul
 
shell scripting can require much more time & cpu resources than awk or perl. e.g, shell:

grep my_file|sed 's/........

requires *nix to fork/exec 2 new processes to execute these utilities.

Doing comparable operations in awk or perl will use only the original process.

If there any looping constructs, shell will re-interpret the script code and repeat the fork/exec's. Perl (& awk?) has 1 compilation pass and then uses an internal byte code, presumably more efficient than re-interpret'ing.

Of course, if your script has no/little looping and/or is not heavily used, there will probably not be measurable difference between an S,P, or A implementation.
 
spyghost

The good thing with perl is that you can reuse the code for a windows platform..probably you could create multiplatform scripts...

e.g. Opening a text file

($^O =~ /Win/ ) ? system("notepad.exe $textfile") : system( "/usr/dt/bin/dtpad -standAlone -noReadOnlyWarning -viewOnly $textfile \&" );


Cheers!

dmazzini
GSM System and Telecomm Consultant

 
My 2d worth

I work in a large organisation with a significant number of servers and a significant number of Admins with differing skill sets. I can assume that anyone with root access will have sufficient skills to understand a shell script but I can't assume that they know perl. This means that shell scripts have a much lower maintenance cost. I ballance this against perl's power and flexibility. My (flexible) rule of thumb is to use shell scripts unless I need the power of perl. To give examples the nightly housekeeping cron jobs
Code:
find / -name core -exec rm {} \;
will always be in shell script. The routine which analyses the sudo log file and e-mails the results to the security team is an obvious perl script. Yes I could have done it in awk but that would have been as difficult for the newbie as a perl script.

Columb Healy
 
...an obvious perl script. Yes I could have done it in awk but..."

*grin* Good lad...

Mike

shows ways to help with Tsunami Relief.

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top