Find the answer to your Linux question:
Results 1 to 5 of 5
Hello, I want to learn a sripting language, but I don't know which one is best for me. I want to use it for simple house keeping tasks on my ...
  1. #1
    Linux User Daan's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    320

    Question Bash or Perl?

    Hello,

    I want to learn a sripting language, but I don't know which one is best for me. I want to use it for simple house keeping tasks on my computer such as renaming of files, sorting files in directories, etc. Maybe one day I'll use scripts also to run my simple C++ programs from. I already know some C++. I can also program in Mathematica and MATLAB.

    Now, when I was in the book store today, I was looking at O'Reily's books on Bash and Perl. Bash seems a logical choice, but I then saw an O'Reily book on Perl for biologists, and since I am myself a biologist, I thought Perl would be good for me. I think its used in science quite often. But then, Bash seems a more straight forward from where I am now, working at the command line and occasionally adapting other people's bash scripts.

    What is your advice?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So these are VERY different languages, with very different intentions.

    So first, they are both scripting languages. This basically means that they are compile-free (you do not produce binaries), and that they are rather high-level and cross-platform. These are features common to all scripting languages.

    Now then. Bash is a shell. It executes commands. Bash scripts are designed to basically automate the execution of all sorts of commands. It has constructs like conditionals and functions, but it does lack a lot of higher level functionality.

    Perl, on the other hand, is a full-fledged programming language. It has similar syntax to shell scripting (as it was designed to appeal to *nix devs), but it has SO many more capabilities, and is also very extendable through the use of modules.

    One of Perl's greatest strengths is in manipulating text, and one application of this is Bioinformatics. Bioinformatics does tend to use Perl very heavily (I worked at the National Institutes of Health for two summers doing it, and everyone there used Perl), though you could use other languages as well. But Perl is a popular choice.

    I don't know how in-depth your C++ knowledge is, but if it's at least moderately good, you should be able to apply that knowledge to learning, say, Perl. In any event, if you want to learn Perl, I suggest that you first pick up a copy of O'Reilly's "Learning Perl", which is a fabulous book, and then probably "Programming Perl" (basically the bible of Perl programming). Once you have a grasp of the language, you can check out the books particularly aimed towards Bioinformatics, which tend to focus more on using the BioPerl project to enhance Bioinformatics-oriented scripts.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    I generally agree with Cabhan's comments.

    I recommend that you learn at least a little of both. The shell scripting will serve you well in any *nix environment.

    The perl scripting language is very rich. You will quickly see:
    TMTOWTDI. There's More Than One Way To Do It, particularly associated with the Perl programming ... Retrieved from "http://en.wiktionary.org/wiki/TMTOWTDI"
    Most people that become serious about perl do get Programming perl after a class or after working through Learning perl. However, often one needs to know the best of the many ways of doing things in perl. That's where the Best Practices come in (see below). I use that and a complex script, perltidy, to help keep me sane (perltidy has come close to making silk purses of my many sow's scripts).

    If you like the style of the book Learning perl, there are two follow-on books, Intermediate perl, and Mastering perl, both about the same size as Learning perl. What one needs from Programming perl can often be found with perldoc:
    DESCRIPTION
    perldoc looks up a piece of documentation in .pod format that is embed-
    ded in the perl installation tree or in a perl script, and displays it ...
    Here is hello, world in shell:
    Code:
    #!/usr/bin/env sh
    
    # @(#) hello,world.sh   Demonstrate infrastructure of shell script.
    
    printf " Hello, world from sh $LOGNAME in $PWD.\n"
    
    exit 0
    and in perl:
    Code:
    #!/usr/bin/env perl
    
    # @(#) hello,world.perl       Demonstrate infrastructure of perl script.
    
    use warnings;
    use strict;
    
    printf " Hello, world from perl.\n";
    
    exit 0;
    I like the fact that my fingers don't need to learn a lot of new tricks: the comments are the same, some of the ways of displaying data are the same, etc. (but most scripts will not look as similar as these do).

    So while there is some common ground between the two, as Cabhan said, shell is good for controlling processes, automating long strings of commands. I think perl shines in dealing with text, particularly complex data structures of text, but will be slower than compiled languages like c and Fortran for heavy-duty arithmetic work. (Another common use of perl is in CGI programs, a different kettle of fish.)

    If you find that perl scripts are inscrutable, you might consider Python (programming language) - Wikipedia, the free encyclopedia, which enforces a more pleasing visual aspect and has seen increased use over the past few years, somewhat at the expense of perl.

    Whatever you choose:
    To apply the Unix philosophy effectively, you'll need more than
    just C in your toolkit. You'll need to learn how to use some of
    Unix's other languages (especially the scripting languages), and
    how to be comfortable mixing multiple languages in specialist
    roles within large program systems.

    The Art of UNIX Programming, Raymond, 2004, page 322
    Best wishes and good luck ... cheers, drl
    Code:
    Title: Perl Best Practices
    Subtitle: Standards and Styles for Developing Maintainable Code
    Author: Damian Conway
    Date: 2005
    Publisher: O'Reilly
    ISBN: 0596001738
    Pages: 500
    Categories: perl, standard, development, scripting, programming
    Comments: 4.5 stars (31 reviews, 2007.12) at Amazon.
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    Linux User Daan's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    320

    Smile

    Thanks for your advice!

    I guess I'll just start of with O'Reilly's Learning the Bash shell, since computer house keeping is what I want to get done now quickly, and the knowledge will come in handy anyway using Linux. I'll see which book I'll get after that.

    Regards,

    Daan

  5. #5
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    not only Perl, other languages, such as Python can also be used to do bioinformatics. In Python, there should be only one obvious way of doing things. Anyway, you might want to check out both, and see which one suits your programming taste. after learning Bash, you can learn 2 of the essential tools that you will often come across, sed and awk here. good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...