Perl Language 从入门到放弃 All In One
Perl Language 从入门到放弃 All In One
🐪 单峰骆驼 ✅
🐫 双峰骆驼 ❌
Perl
script.pl
#!/usr/bin/perl
# 打印输出 "Hello, World"
print "Hello, World!\n";
#!/usr/bin/perl -w
# 打印输出 "Hello, World"
print "Hello, World!\n";
key | value |
---|---|
Typing discipline | Dynamic |
Implementation language | C |
Filename extensions | .plx, .pl , .pm , .xs, .t , .pod, .cgi |
https://en.wikipedia.org/wiki/Perl
GitHub
.pl
扩展名
# Unix / Linux / macOS
$ perl script.pl
或
# Windows / DOS
C:>perl script.pl
https://www.runoob.com/perl/perl-environment.html
Perl Module
https://github.com/Perl/perl5/blob/blead/lib/User/grent.pm
Perl Test ?
https://github.com/Perl/perl5/blob/blead/lib/User/grent.t
https://github.com/topics/perl
https://github.com/trending/perl
git hooks
脚本语言
#!/usr/bin/perl
#!/usr/bin/perl -w
#!/bin/sh
echo "\n🎉\$1 = $1"
echo "\$2 = $2"
echo "\$3 = $3"
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
echo "\n👻\$1 = $1"
echo "\$2 = $2"
echo "\$3 = $3"
Perl 教程
Perl 是 Practical Extraction and Report Language
的缩写,可翻译为 "实用报表提取语言
"。
Perl 是高级、通用、直译式、动态的程序语言。
Perl 最初的设计者为拉里·沃尔(Larry Wall),于1987年12月18日发表。
Perl 借用了C、sed、awk、shell脚本以及很多其他编程语言的特性。
Perl 最重要的特性是Perl内部集成了正则表达式的功能,以及巨大的第三方代码库 CPAN
。
https://www.runoob.com/perl/perl-tutorial.html
Perl 简介
Perl,一种功能丰富的计算机程序语言,运行在超过100种计算机平台上,适用广泛,从大型机到便携设备,从快速原型创建到大规模可扩展开发。
Perl 语言的应用范围很广,除CGI以外,Perl被用于图形编程、系统管理、网络编程、金融、生物以及其他领域。由于其灵活性,Perl被称为脚本语言
中的瑞士军刀
。
Perl 是可扩展的,我们可以通过 CPAN("the Comprehensive Perl Archive Network"全面的 Perl 存档网络)中心仓库找到很多我们需要的模块。
https://www.runoob.com/perl/perl-intro.html
Perl 基础语法
#!/usr/bin/perl
# 这是一个单行注释
print "Hello, world\n";
=pod 注释
这是一个多行注释
这是一个多行注释
这是一个多行注释
这是一个多行注释
=cut
#!/usr/bin/perl
print "Hello, world\n"; # 双引号
print 'Hello, world\n'; # 单引号
从结果中我们可以看出,双引号 \n 输出了换行,而单引号没有。
Perl双引号和单引号的区别: 双引号可以正常解析一些转义字符与变量,而单引号无法解析会原样输出。
#!/usr/bin/perl
$a = 10;
$var = <<"EOF";
这是一个 Here 文档实例,使用双引号。
可以在这输入字符串和变量。
例如:a = $a
EOF
print "$var\n";
$var = <<'EOF';
这是一个 Here 文档实例,使用单引号。
例如:a = $a
EOF
print "$var\n";
Here 文档
Here文档又称作 heredoc
、hereis、here-字串或here-脚本,是一种在命令行shell(如sh、csh、ksh、bash、PowerShell和zsh)和程序语言(像Perl、PHP、Python和Ruby)里定义一个字串的方法。
使用概述:
1.必须后接分号,否则编译通不过。
2.END可以用任意其它字符代替,只需保证结束标识与开始标识一致。
3.结束标识必须顶格独自占一行(即必须从行首开始,前后不能衔接任何空白和字符)。
4.开始标识可以不带引号号或带单双引号,不带引号与带双引号效果一致,解释内嵌的变量和转义符号,带单引号则不解释内嵌的变量和转义符号。
5.当内容需要内嵌引号(单引号或双引号)时,不需要加转义符,本身对单双引号转义,此处相当与q和qq的用法。
https://www.runoob.com/perl/perl-syntax.html
CPAN
the Comprehensive Perl Archive Network / 全面的 Perl 存档网络 / 综合 Perl 档案网络
here document
here-document, here-text, heredoc
, hereis, here-string or here-script
https://en.wikipedia.org/wiki/Here_document
https://linuxize.com/post/bash-heredoc/
<< EOF
???
???
???
EOF
ES6
https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_–_ECMAScript_2015
https://en.wikipedia.org/wiki/Escape_character
const apples = 4;
const bananas = 3;
console.log(`I have ${apples} apples`);
console.log(`
I have
${apples} apples
${bananas} bananas
total: ${apples + bananas} fruit.
`);
https://en.wikipedia.org/wiki/String_interpolation#JavaScript
macOS & Perl
macOS Perl
/usr/bin/perl --version
This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2020, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
➜ ~ /usr/bin/perl -V
Summary of my perl5 (revision 5 version 30 subversion 3) configuration:
Platform:
osname=darwin
osvers=21.0
archname=darwin-thread-multi-2level
uname='darwin smwk2.p1s.plx.sd.apple.com 21.0 darwin kernel version 20.1.0: wed nov 3 12:44:24 pdt 2021; root:xnu-7195.41.8.100.10~1development_x86_64 x86_64 '
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=cc'
hint=recommended
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
bincompat5005=undef
Compiler:
cc='cc'
ccflags =' -g -pipe -fno-strict-aliasing -fstack-protector-strong -DPERL_USE_SAFE_PUTENV'
optimize='-Os'
cppflags='-g -pipe -fno-strict-aliasing -fstack-protector-strong'
ccversion=''
gccversion='Apple LLVM 13.1.6 (clang-1316.0.20.6) [+internal-os, ptrauth-isa=deployment-target-based]'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='cc'
ldflags =' -fstack-protector-strong'
libpth=/AppleInternal/Library/BuildRoots/66382bca-8bca-11ec-aade-6613bcf0e2ee/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.Internal.sdk/usr/local/lib /AppleInternal/Library/BuildRoots/66382bca-8bca-11ec-aade-6613bcf0e2ee/Applications/Xcode.app/Contents/Developer/Toolchains/OSX12.3.xctoolchain/usr/lib/clang/13.1.6/lib /AppleInternal/Library/BuildRoots/66382bca-8bca-11ec-aade-6613bcf0e2ee/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.Internal.sdk/usr/lib /AppleInternal/Library/BuildRoots/66382bca-8bca-11ec-aade-6613bcf0e2ee/Applications/Xcode.app/Contents/Developer/Toolchains/OSX12.3.xctoolchain/usr/lib /AppleInternal/Library/BuildRoots/66382bca-8bca-11ec-aade-6613bcf0e2ee/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib /usr/local/lib
libs=
perllibs=
libc=
so=dylib
useshrplib=true
libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=bundle
d_dlsymun=undef
ccdlflags=' '
cccdlflags=' '
lddlflags=' -bundle -undefined dynamic_lookup -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
HAS_TIMES
MULTIPLICITY
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_ITHREADS
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
USE_REENTRANT_API
USE_THREAD_SAFE_LOCALE
Locally applied patches:
/Library/Perl/Updates/<version> comes before system perl directories
installprivlib and installarchlib points to the Updates directory
Built under darwin
Compiled at Feb 12 2022 01:42:25
@INC:
/Library/Perl/5.30/darwin-thread-multi-2level
/Library/Perl/5.30
/Network/Library/Perl/5.30/darwin-thread-multi-2level
/Network/Library/Perl/5.30
/Library/Perl/Updates/5.30.3
/System/Library/Perl/5.30/darwin-thread-multi-2level
/System/Library/Perl/5.30
/System/Library/Perl/Extras/5.30/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.30
➜ ~
refs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16823456.html
未经授权禁止转载,违者必究!