【课程-Perl】Lesson 1: Perl 脚本的框架

本文内容:

  1. 理解什么是Perl脚本
  2. 下载安装用来写Perl脚本的文本编辑器gedit
  3. 练习写简单的Perl脚本
  4. 用终端运行Perl interpreter
    ——————————————

Perl被广泛运用到解决DNA或者蛋白质的序列问题,文件格式转换,以及一些计算机上的重复工作。然而Per语言只是解决以上问题的编程语言其中之一。

Perl在Macs和Linux系统中是预先安装好的。 使用PC的可以自行安装(用苹果的同学暗地里偷笑)http://www.perl.org/get.html#win32 或者 http://strawberryperl.com

Perl语言被设计像真正的语言一样,和我们说的语言类似。一件事情可以通过不同方式来表述,在Perl里面你也可以以不同的方式解决一个问题。Perl的座右铭就是“There is more than one way to do it” https://en.wikipedia.org/wiki/There’s_more_than_one_way_to_do_it 。当然,这也即成为了Perl的优势也是它的劣势。一方面,Perl可以很容易的被各个领域采用,比如BBC,亚马逊,以及人类基因组项目课题。另一方面,Perl语言由于方式多变而被滥用。

本次课程包括基本的Perl词汇和语法,来解决一些简单的生物信息案例。如果你没有编程基础也没关系,这个适合初学者。

Perl程序(也叫做脚本)就是储存一系列的指令说明的文本文件。因为计算机不能直接理解Perl,所以我们的脚本必须要通过叫做Perl interpreter的程序处理,将脚本翻译成机器语言。Perl interpreter是通过command line(命令行)来运行的。如果打算开始掌握Perl,我们必须熟练使用command line。

以下是实际操作练习。

  1. 使用文本编辑器gedit (下载 http://macappstore.org/gedit/

Install the App gedit:

Press Command+Space and type Terminal and press enter/return key.

Run in Terminal app:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null

and press enter/return key.

If the screen prompts you to enter a password, please enter your Mac’s user password to continue. When you type the password, it won’t be displayed on screen, but the system would accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.

Run:

brew cask install gedit

(Just an alternate suggestion for OSX Sierra users. If the following doesn’t work for you:

$brew cask install gedit

Try the following instead:

$brew install gedit)

当安装好 gedit后,在终端输入gedit就会自动弹出文本编辑器gedit的窗口。在光标处输入

print "Once information has passed into protein it cannot get out again\n";

《【课程-Perl】Lesson 1: Perl 脚本的框架》 Screen Shot 2018-04-10 at 14.16.34.png

(\n 表示移动到下一行;# 后面是自己的注释,不会被读写和输出;
use warnings 可以在运行出现问题时进行提醒,也可以在运行Perl interpreter时候加入一个-w的参数; use strict 通常会要求添加这个在每个脚本里,用来告诉Perl interpreter来抱怨当你用了非常危险的Perl符号,不关键,总之有比没有强),

并且保存文本文档到一个自己制定的文件夹位置,命名为“central_dogma.pl”。接下来从终端进入到刚刚保存Pear脚本到文件夹 (Enter the command pwd (on Linux or Mac) or cd (on Windows) to see which directory you are in; use the command ls (on Linux or Mac) or dir (on Windows) to see what the directory contains)

  1. 运行Perl interpreter,通过键入:perl central_dogma.pl

就会看到结果输出。或者perl -w central_dogma.pl,后者会有错误提醒。

【此系列内容属于学习笔记】
版权©️: http://nbviewer.jupyter.org/github/grsr/perl-course/blob/master/Learning_Perl.ipynb

    原文作者:Runuply
    原文地址: https://www.jianshu.com/p/6f7d11438303
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞