测试 perl 安装_测试您的Perl安装

测试 perl 安装

In order to test our fresh installation of Perl, we'll need a simple Perl program. The first thing most new programmers learn is how to make the script say 'Hello World'. Let's look at a simple Perl script that does just that.

为了测试我们全新安装的Perl,我们需要一个简单的Perl程序。 大多数新程序员学习的第一件事是如何使脚本说“ Hello World ”。 让我们看一个简单的Perl脚本。


#!/usr/bin/perl
print "Hello World.\n";

The first line is there to tell the computer where the Perl interpreter is located. Perl is an interpreted language, which means that rather than compiling our programs, we use the Perl interpreter to run them. This first line is usually #!/usr/bin/perl or #!/usr/local/bin/perl, but depends on how Perl was installed on your system.

第一行是那里说不出哪里 Perl解释器所在的计算机。 Perl是一种解释性语言,这意味着我们使用Perl解释器来运行它们,而不是编译程序。 第一行通常是#!/ usr / bin / perl#!/ usr / local / bin / perl ,但要取决于系统上Perl的安装方式。

The second line tells the Perl interpreter to print the words 'Hello World.' followed by a newline (a carriage return). If our Perl installation is working correctly, then when we run the program, we should see the following output:

第二行告诉Perl解释器打印单词“ Hello World”。 ',后跟换行符 (回车)。 如果我们的Perl安装正常运行,那么在运行程序时,我们应该看到以下输出:


Hello World.

Testing your Perl installation is different depending on the type of system you are using, but we'll take a look at the two most common situations:

根据您所使用的系统类型,对Perl安装的测试有所不同,但我们将介绍两种最常见的情况:

  1. Testing Perl on Windows (ActivePerl)

    Windows上测试Perl(ActivePerl)

  2. Testing Perl on *nix Systems

    在* nix系统上测试Perl

The first thing you'll want to do is make sure you've followed the ActivePerl Installation tutorial and installed ActivePerl and the Perl Package Manager on your machine. Next, create a folder on your C: drive to store your scripts in -- for the sake of the tutorial, we'll call this folder perlscripts. Copy the 'Hello World' program into C:\perlscripts\ and make sure the filename is hello.pl.

您要做的第一件事是确保您已遵循ActivePerl安装教程 ,并在计算机上安装了ActivePerl和Perl软件包管理器。 接下来,在C:驱动器上创建一个文件夹,用于将脚本存储在-为了本教程的缘故,我们将此文件夹称为perlscripts 。 将“ Hello World”程序复制到C:\ perlscripts \,并确保文件名是hello.pl

获取Windows命令提示符 ( Getting a Windows Command Prompt )

Now we need to get to a Windows command prompt. Do this by clicking on the Start menu and selecting the item Run.... This will pop up the run screen that contains the Open: line. From here, just type cmd into the Open: field and press the Enter key. This will open (yet another) window which is our Windows command prompt. You should see something like this:

现在我们需要进入Windows命令提示符。 通过单击“ 开始”菜单并选择“ 运行...”来执行此操作。 这将弹出包含“ 打开:”行的运行屏幕。 在这里,只需在“ 打开:”字段中键入cmd ,然后按Enter键。 这将打开(还有另一个)窗口,这是我们的Windows命令提示符。 您应该会看到以下内容:


Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\perlguide\Desktop>

We need to change to the directory (cd) that contains our Perl scripts by typing in the following command:

我们需要通过输入以下命令来更改包含Perl脚本的目录(cd):


cd c:\perlscripts

That should make our prompt reflect the change in the path like so:

这应该使我们的提示反映出路径的变化,如下所示:


C:\perlscripts>

Now that we're in the same directory as the script, we can run it simply by typing its name at the command prompt:

现在,我们与脚本位于同一目录中,我们只需在命令提示符下键入其名称即可运行它:


hello.pl

If Perl is installed and running correctly, it should output the phrase 'Hello World.', and then return you to the Windows command prompt.

如果Perl已安装并正确运行,则应输出短语“ Hello World。”,然后将您返回Windows命令提示符。

An alternate method of testing your Perl installation is by running the interpreter itself with the -v flag:

测试您的Perl安装的另一种方法是通过使用-v标志运行解释器本身:


perl -v

If the Perl interpreter is working correctly, this should output quite a bit of information, including the current version of Perl you are running.

如果Perl解释器正常工作,这应该输出很多信息,包括您正在运行的Perl的当前版本。

测试安装 ( Testing Your Installation )

If you are using a school or work Unix / Linux server, chances are Perl is already installed and running -- when in doubt, just ask your system administrator or technical staff. There are a few ways we can test our installation, but first, you will need to complete two preliminary steps.​

如果您正在使用学校或上班的Unix / Linux服务器,则可能已经安装并正在运行Perl -如有疑问,请询问系统管理员或技术人员。 我们可以通过几种方法来测试安装,但是首先,您需要完成两个初步步骤。

First, you must copy your 'Hello World' program to your home directory. This is usually accomplished via FTP. 

首先,您必须将“ Hello World”程序复制到主目录。 通常,这是通过FTP完成的。

Once your script has been copied to your server, you will need to get to a shell prompt on the machine, usually via SSH. When you have reached the command prompt, you can change into your home directory by typing the following command:

将脚本复制到服务器后,通常需要通过SSH进入计算机上的Shell提示符 。 到达命令提示符后,可以通过键入以下命令进入目录:


cd ~

Once there, testing your Perl installation is very similar to testing on a windows system with one extra step. In order to execute the program, you must first tell the operating system that the file is OK to execute. This is done by setting the permissions on the script so that anyone can execute it. You can do this by using the chmod command:

到那里之后,测试您的Perl安装与在Windows系统上进行测试非常相似,只需要多一步。 为了执行程序,您必须首先告诉操作系统该文件可以执行。 这是通过在脚本上设置权限来完成的,这样任何人都可以执行它。 您可以使用chmod命令执行此操作:


chmod 755 hello.pl

Once you've set the permissions, you can then execute the script by simply typing its name.

设置权限后,您只需键入名称即可执行脚本。


hello.pl

If that doesn't work, you might not have your home directory in your current path. As long as you are in the same directory as the script, you can tell the operating system to run the program (in the current directory) like so:

如果这不起作用,则您的当前路径中可能没有主目录。 只要您与脚本位于同一目录中,就可以告诉操作系统运行程序(在当前目录中),如下所示:


./hello.pl

If Perl is installed and running correctly, it should output the phrase 'Hello World.', and then return you to the Windows command prompt.

如果Perl已安装并正确运行,则应输出短语“ Hello World。”,然后将您返回Windows命令提示符。

An alternate method of testing your Perl installation is by running the interpreter itself with the -v flag:

测试您的Perl安装的另一种方法是通过使用-v标志运行解释器本身:


perl -v

If the Perl interpreter is working correctly, this should output quite a bit of information, including the current version of Perl you are running.

如果Perl解释器正常工作,这应该输出很多信息,包括您正在运行的Perl的当前版本。

翻译自: https://www.thoughtco.com/testing-your-perl-installation-2641099

测试 perl 安装

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值