Perl初學筆記之Hello World_perl

來源:互聯網
上載者:User

工作需要開始學Perl,下載個Window版(5.16)的: 下載連結
http://www.activestate.com/activeperl/downloads
安裝好了之後,寫第一個perl程式

複製代碼 代碼如下:

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

運行結果: (很像Python哦)
複製代碼 代碼如下:

c:\Perl>perl HelloWorld.pl 
Hello,World!

接著學了下:cpan,雖然不知道這傢伙具體是幹嘛,應該是能安裝各種包,9000多種。
命令如下:看第二次輸出的結果,應該是類似於資料庫的東東吧。
複製代碼 代碼如下:

c:\Perl>cpan App::cpanminus 
Set up gcc environment - 3.4.5 (mingw-vista special r3) 
CPAN: Term::ANSIColor loaded ok (v4.02) 
CPAN: Storable loaded ok (v2.34) 
Reading 'C:\Perl\cpan\Metadata' 
Database was generated on Fri, 07 Mar 2014 13:06:13 GMT 
CPAN: Module::CoreList loaded ok (v2.80) 
App::cpanminus is up to date (1.7001). 

然後用cpanm安裝模組,命令如下: (cpanm Module::Name)
複製代碼 代碼如下:

c:\Perl>cpanm YAML 
Set up gcc environment - 3.4.5 (mingw-vista special r3) 
--> Working on YAML 
Fetching http://www.cpan.org/authors/id/I/IN/INGY/YAML-0.90.tar.gz ... OK 
Configuring YAML-0.90 ... OK 
Building and testing YAML-0.90 ... OK 
Successfully installed YAML-0.90 
1 distribution installed 

如果實在不曉得如何用的話: cpanm --help    //-->會看到很多提示。
複製代碼 代碼如下:

c:\Perl>cpanm --help 
Set up gcc environment - 3.4.5 (mingw-vista special r3) 
Usage: cpanm [options] Module [...] 
 
Options: 
  -v,--verbose              Turns on chatty output 
  -q,--quiet                Turns off the most output 

看上面的安裝過程,好像是可以執行cpanm Link,果然是可以:
複製代碼 代碼如下:

c:\Perl>cpanm http://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Alt-Base-0.0 
2.tar.gz 
Set up gcc environment - 3.4.5 (mingw-vista special r3) 
--> Working on http://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Alt-Base-0. 
02.tar.gz 
Fetching http://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Alt-Base-0.02.tar 
.gz ... OK 
Configuring Alt-Base-0.02 ... OK 
==> Found dependencies: Alt 
--> Working on Alt 
Fetching http://www.cpan.org/authors/id/I/IN/INGY/Alt-0.04.tar.gz ... OK 
Configuring Alt-0.04 ... OK 
Building and testing Alt-0.04 ... OK 
Successfully installed Alt-0.04 
Building and testing Alt-Base-0.02 ... OK 
Successfully installed Alt-Base-0.02 
2 distributions installed 

然後開始寫了個檔案操作的指令碼,裡面有個Path::Class模組。
複製代碼 代碼如下:

use Path::Class; 
C:\Perl\Learn>perl FindFile.pl 
Can't locate Path/Class.pm in @INC (@INC contains: C:/Perl/site/lib/MSWin32-x86- 
multi-thread C:/Perl/site/lib C:/Perl/lib .) at FindFile.pl line 4. 
BEGIN failed--compilation aborted at FindFile.pl line 4. 

看提示,像沒有安裝該包,安裝了下該包,結果果然沒報這種錯誤:
複製代碼 代碼如下:

C:\Perl\Learn>cpanm Path::Class 
Set up gcc environment - 3.4.5 (mingw-vista special r3) 
--> Working on Path::Class 
Fetching http://www.cpan.org/authors/id/K/KW/KWILLIAMS/Path-Class-0.33.tar.gz .. 
. OK 
Configuring Path-Class-0.33 ... OK 
Building and testing Path-Class-0.33 ... OK 
Successfully installed Path-Class-0.33 
1 distribution installed 

完~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.