Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Programming Perl for Geoscientists
Programming Perl for Geoscientists
Programming Perl for Geoscientists
Ebook316 pages2 hours

Programming Perl for Geoscientists

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Perl, which stands for Practical Extraction and Reporting Language, is a scripting language originally developed by Larry Wall in 1987. It was meant for text manipulation, but now it is used for a wide range of tasks, including system administration, Web development, network programming, GUI development, and more. Whether you’re an information technology professional, a student, or an executive seeking to utilize Perl to help your organization, this book will help you to understand exactly what Perl is and how it can be used in various fields. Throughout the book, you’ll find examples, figures, and instructions on where you can find additional information online so you can effectively use Perl. Whether you’re working with vast amounts of information generated from seismic surveys, in the oil industry or another field, you’ll get essential tools with Programming Perl for Geoscientists.
LanguageEnglish
Release dateMar 13, 2015
ISBN9781483418421
Programming Perl for Geoscientists

Related to Programming Perl for Geoscientists

Related ebooks

Computers For You

View More

Related articles

Reviews for Programming Perl for Geoscientists

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Programming Perl for Geoscientists - Dorian Oria San Martin

    Martin

    Copyright © 2015 Dorian Oria San Martin.

    Proofreading: Lina Andrea Preciado Cano

    All rights reserved. No part of this book may be reproduced, stored, or transmitted by any means—whether auditory, graphic, mechanical, or electronic—without written permission of both publisher and author, except in the case of brief excerpts used in critical articles and reviews. Unauthorized reproduction of any part of this work is illegal and is punishable by law.

    ISBN: 978-1-4834-1843-8 (sc)

    ISBN: 978-1-4834-1842-1 (e)

    Library of Congress Control Number: 2015900636

    Because of the dynamic nature of the Internet, any web addresses or links contained in this book may have changed since publication and may no longer be valid. The views expressed in this work are solely those of the author and do not necessarily reflect the views of the publisher, and the publisher hereby disclaims any responsibility for them.

    Any people depicted in stock imagery provided by Thinkstock are models, and such images are being used for illustrative purposes only.

    Certain stock imagery © Thinkstock.

    Lulu Publishing Services rev. date: 02/27/2015

    Contents

    Another introduction

    Chapter 1:   Introduction

    Chapter 2:   Variable Types & Operators

    Chapter 3:   Control Structures

    Chapter 4:   Arrays and hashes

    Chapter 5:   3Handling text files

    Chapter 6:   Subroutines & Modules

    Chapter 7:   The power of Perl Tk

    Chapter 8:   Well logs

    Chapter 9:   Velocity model files

    Chapter 10:   SEG-Y files

    Chapter 11:   Seismic Data Acquisition

    Chapter 12:   SEG-D files

    References

    To all women who accompany me: Shakti Ma, Anama, Blanca Estela, Coralí, Jolda.

    To all women who accompanied me: Daisy, Enriqueta, Carolina

    To all who went and to all who stayed.

    To all who were nice to me and those who were not

    To my children Victor, Valentina and Surya

    To life!

    Another introduction

    In 2008, I began to write this book in English. During the nights, when I was free from my activities as Quality Control Chief in a seismic data marine acquisition, I used to work until very early in the morning, when I consider it is my best time to write. That first version was almost done in the middle of 2009 but the death of my first wife shocked me. Besides the terrible pain I was feeling, that fact meant an interruption of all the projects I had been working in, including this book.

    I moved to Colombia in 2010 and looked for a way that could help me to ease my deep pain. The next year, I started to study in the Gestalt Claudio Naranjo School ‘Transformación Humana.’ In a weekend course of familiar constellations, the instructor, Ramón Resino, suggested that I should honor my profession by concluding this book. Although I said yes, to finish the book would take more time.

    The decision to keep writing until the end was taken at the beginning of 2013, motivated by the need to ‘close the pending issues’, instead of just the enthusiasm for finishing it up. The most beautiful thing in all of this process was when I restarted the project, which I loved and enjoyed to work on.

    Thinking about the ‘honoring my profession’ fact, I wrote the biggest part of the book in my native language, Spanish. I had to rewrite many scripts to adapt them to the new version of Perl Tk, Perl Tkx, because the one I used to work with was changed by ActiveState.

    For this version you are about to read, I returned to the origin: Perl Tk. That let me to add scripts that were not possible for me to do when I wrote in Perl Tkx. Personally, I think that Perl Tk is much better than Perl Tkx, and I still prefer the first one.

    I know how audacious it is to write this book in English. However, I believe that the programming languages are like math: they are a universal language. It does not matter which language you speak, you will be able to understand the scripts and the explanations, or at least I really hope so.

    Anyway, here you have the result and I hope it will be useful for you.

    I want to express my deepest gratitude to my wife, Ana Maria, who was always motivating and, in many cases, pushing me to finish it. When it was done, I felt that she was happier than me.

    In addition, I want to thank my spiritual masters, from whom I receive the energy and inspiration to do what I do. In spite that this could be earthly, I have no doubt that the knowledge shown here comes from them.

    OM NAMAHA SHIVAYA

    Chapter 1

    Introduction

    1.1  A brief history of Perl

    Perl is a script language created by Larry Wall, who released the first version in 1987 to the comp.sources.misc newsgroup. The language expanded rapidly over the next few years.

    The reason for its creation was that Wall was unhappy by the functionality that sed, C, awk and the Bourne Shell offered him. He looked for a language that will combine all of their best features, while having as few disadvantages of its own.

    The last version of Perl was released in 1994. This version was a complete re-write of the Perl interpreter, and introduced such things as hard references, modules, objects and lexical scoping. Several minor versions of Perl have appeared since then, and the most up-to-date stable version (as of October 2005) is 5.14.x.

    1.2  Why Perl?

    Perl is the abbreviation of Practical Extraction and Report Language. Perl was originally named ‘Pearl’, after the Parable of the Pearl from the Gospel of Matthew. Larry Wall wanted to give the language a short name with positive connotations; he claims that he considered (and rejected) every word with three and four letters in the dictionary. He also considered naming it after his wife Gloria.

    1.3  Overview

    Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.

    The language is intended to be practical (easy to use, efficient and complete) rather than beautiful (tiny, elegant and minimal). Its major features include the support for multiple programming paradigms (procedural, object-oriented, and functional styles), reference counting memory management (without a cycle detecting garbage collector), built-in support for text processing, and a large collection of third-party modules.

    1.4  Features

    The overall structure of Perl derives broadly from C. Perl is procedural in nature, with variables, expressions, assignment statements, brace-delimited code blocks, control structures, and subroutines.

    Perl also takes features from shell programming. All variables are marked with leading sigils, which unambiguously identifies the data type (scalar, array, hash, etc.) of the variable in context. Importantly, sigils allow variables to be interpolated directly into strings. Perl has many built-in functions, which provide tools often used in shell programming (though many of these tools are implemented by programs external to the shell) like sorting, and calling on system facilities.

    Other important features are:

    √ Perl takes the best features from other languages, such as C, awk, sed, sh, and BASIC, among others.

    √ Perl’s database integration interface (DBI) supports third-party databases including Oracle, Sybase, Postgres, MySQL and others.

    √ Perl works with HTML, XML, and other mark-up languages.

    √ Perl supports Unicode.

    √ Perl is Y2K compliant.

    √ Perl supports both procedural and object-oriented programming.

    √ Perl interfaces with external C/C++ libraries through XS or SWIG.

    √ Perl is extensible. There are over 500 third party modules available from the Comprehensive Perl Archive Network (CPAN).

    √ The Perl interpreter can be embedded into other systems.

    1.5  Resources

    It is possible to find several Perl binary distributions, ready to be used, in several operative systems, including Linux, Mac OS X and Windows. Some of them are available in:

    - http://strawberryperl.com/ (for Windows)

    - http://www.activestate.com/ (Windows, Linux, Mac OS X)

    - http://dwimperl.com/ (Windows, Linux)

    - http://www.citrusperl.com/ (Windows, Linux, Mac OS X)

    However, many Linux distributions and the last Mac OS X versions come with Perl installed.

    Windows does not come with Perl installed.

    In ActiveState is possible to find binary modules, ready to be used.

    The project CPAN (Comprehensive Perl Archive Network), at the time of writing, has 124,342 modules available. In chapter 6 it is explained how to install modules from CPAN.

    I used to work with the Perl version available in http://www.activestate.com/. On this web site it is possible to find binary versions for Windows, Solaris, Mac, Linux. They have a lot of binary modules as well, ready to be used.

    However, I installed the Perl version available for Windows from http://strawberryperl.com/ for testing the scripts, and I liked it!

    I wrote this book using a MacBook Air computer. To run the scripts, I used the Perl version 5.16.0. The most recent version and the instructions to install it can be found at http://learn.perl.org/installing/.

    1.6  Installing Perl Tk

    Before, I mentioned the sites where it is possible to find Perl installer. Some of them are full versions, which means that they include compiled versions of the component Perl-Tk (i.e. the ActiveState distribution.) In the case of the distribution available in ActiveState, now Perl-Tk changed to Perl-Tkx. All the scripts shown and explained in chapter 7, are related to GUI (Graphical User Interfaces) and were written using Perl-Tk. However, all of them have a similar version in Perl-Tkx, available in the distribution of this book.

    To reproduce the exercises shown here, I will explain how to install Perl-Tk in the most common OS: Linux, Windows and Mac OS X.

    PCs with Linux and Mac OS X come with Perl installed, except Perl-Tk. In the case of Windows, I suggest to install the Perl interpreter available at http://strawberryperl.com/. Next, I will explain how to install Perl-Tk in these OSs.

    In a terminal window (Command Prompt in Windows) write the following instructions (in Mac and Linux, you must do this as super user):

    perl -MCPAN -e shell

    After this, you will see the cpan prompt (figure 1.1, enclosed in a rectangle)

    007_a_gg.jpg

    Figure 1.1 Installing Perl-Tk

    In the cpan prompt, write the following instructions:

    cpan> install Bundle::CPAN

    cpan> reload cpan

    cpan> install Tk

    In case the installation fails, use the instruction:

    cpan> force install Tk

    1.7  IDE’s for PERL

    Perl is an interpreted language. With this, you can make scripts. So, you can write them using a text editor, such as notepad, gedit or WordPad. However, it is possible to find several IDEs which make it easy to write Perl scripts. Some of them are free of charge and others are not. Some free options are below.

    1.7.1  Open Perl IDE

    This is one of the best free Perl IDEs avaliable. It can be downloaded from: http://open-perl-ide.sourceforge.net/. In the link it is possible to find all the training material needed.

    1.7.2  Perl Express

    Another interesting Perl IDE is Perl Express. This can be downloaded from: http://www.perl-express.com/. On its web site, it is possible to find all the necessary information to work with it.

    1.7.3  Notepad++

    This is the editor I prefer to use. It can be downloaded from http://notepad-plus-plus.org/.

    1.7.4  gedit

    This editor comes with many Linux distributions. It is able to recognize the instructions of Perl scripts, so this is very useful to check syntax.

    1.7.5  Komodo IDE

    I use this IDE in making the script in Mac OS X. It is available for free and available for Windows and Linux, as well. It can be downloaded from: http://www.activestate.com/komodo-ide. Figure 1.2 below shows how the IDE looks.

    009_b_gg.jpg

    Figure 1.2 Komodo IDE

    1.7.6  Padre

    This is an integrated development environment or, in other words, a text editor that is simple to use for new Perl programmers but also supports large multi-lingual and

    Enjoying the preview?
    Page 1 of 1