Perl Special Variables

Some variables have a predefined and special meaning in Perl. They are the variables that use punctuation characters after the usual variable indicator ($, @, or %), such as $_. The explicit, long-form names shown are the variables' equivalents when you use the English module by including "use English;" at the top of your program.

4.4.1 Global Special Variables

The most commonly used special variable is $_, which contains the default input and pattern-searching string. For example, in the following lines:

foreach ('hickory','dickory','doc') {
	print;
}
The first time the loop is executed, "hickory" is printed. The second time around, "dickory" is printed, and the third time, "doc" is printed. That's because in each iteration of the loop, the current string is placed in $_, and is used by default by print. Here are the places where Perl will assume $_ even if you don't specify it:
  • Various unary functions, including functions like ord and int, as well as the all file tests (-f, -d) except for -t, which defaults to STDIN.

  • Various list functions like print and unlink.

  • The pattern-matching operations m//, s///, and tr/// when used without an =~ operator.

  • The default iterator variable in a foreach loop if no other variable is supplied.

  • The implicit iterator variable in the grep and map functions.

  • The default place to put an input record when a line-input operation's result is tested by itself as the sole criterion of a while test (i.e., <filehandle>). Note that outside of a while test, this will not happen.

The following is a complete listing of global special variables:

$_ $ARG

The default input and pattern-searching space.

$. $INPUT_LINE_NUMBER

$NR

The current input line number of the last filehandle that was read. An explicit close on the filehandle resets the line number.

$/ $INPUT_RECORD_SEPARATOR

$RS

The input record separator; newline by default. If set to the null string, it treats blank lines as delimiters.

$, $OUTPUT_FIELD_SEPARATOR

$OFS

The output field separator for the print operator.

$\ $OUTPUT_RECORD_SEPARATOR $ORS

The output record separator for the print operator.

$ $LIST_SEPARATOR

Like "$," except that it applies to list values interpolated into a double-quoted string (or similar interpreted string). Default is a space.

$; $SUBSCRIPT_SEPARATOR $SUBSEP

The subscript separator for multidimensional array emulation. Default is "\034".

$^L $FORMAT_FORMFEED

What a format outputs to perform a formfeed. Default is "\f".

$: $FORMAT_LINE_BREAK_CHARACTERS

The current set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format. Default is "\n"".

$^A $ACCUMULATOR

The current value of the write accumulator for format lines.

$# $OFMT

Contains the output format for printed numbers (deprecated).

$? $CHILD_ERROR

The status returned by the last pipe close, backtick (``) command, or system operator.

$! $OS_ERROR $ERRNO

If used in a numeric context, yields the current value of the errno variable, identifying the last system call error. If used in a string context, yields the corresponding system error string.

$@ $EVAL_ERROR

The Perl syntax error message from the last eval command.

$$ $PROCESS_ID $PID

The pid of the Perl process running this script.

$< $REAL_USER_ID $UID

The real user ID (uid) of this process.

$> $EFFECTIVE_USER_ID $EUID

The effective uid of this process.

$( $REAL_GROUP_ID $GID

The real group ID (gid) of this process.

$) $EFFECTIVE_GROUP_ID $EGID

The effective gid of this process.

$0 $PROGRAM_NAME

Contains the name of the file containing the Perl script being executed.

$[

The index of the first element in an array and of the first character in a substring. Default is 0.

$] $PERL_VERSION

Returns the version plus patchlevel divided by 1000.

$^D $DEBUGGING

The current value of the debugging flags.

$^E $EXTENDED_OS_ERROR

Extended error message on some platforms.

$^F $SYSTEM_FD_MAX

The maximum system file descriptor, ordinarily 2.

$^H

Contains internal compiler hints enabled by certain pragmatic modules.

$^I $INPLACE_EDIT

The current value of the inplace-edit extension. Use undef to disable inplace editing.

$^M

The contents of $M can be used as an emergency memory pool in case Perl dies with an out-of-memory error. Use of $M requires a special compilation of Perl. See the INSTALL document for more information.

$^O $OSNAME

Contains the name of the operating system that the current Perl binary was compiled for.

$^P $PERLDB

The internal flag that the debugger clears so that it doesn't debug itself.

$^T $BASETIME

The time at which the script began running, in seconds since the epoch.

$^W $WARNING

The current value of the warning switch, either true or false.

$^X $EXECUTABLE_NAME

The name that the Perl binary itself was executed as.

$ARGV

Contains the name of the current file when reading from <ARGV>.

4.4.2 Global Special Arrays and Hashes

@ARGV

The array containing the command-line arguments intended for the script.

@INC

The array containing the list of places to look for Perl scripts to be evaluated by the do, require, or use constructs.

@F

The array into which the input lines are split when the -a command-line switch is given.

%INC

The hash containing entries for the filename of each file that has been included via do or require.

%ENV

The hash containing your current environment.

%SIG

The hash used to set signal handlers for various signals.

4.4.3 Global Special Filehandles

ARGV

The special filehandle that iterates over command line filenames in @ARGV. Usually written as the null filehandle in <>.

STDERR

The special filehandle for standard error in any package.

STDIN

The special filehandle for standard input in any package.

STDOUT

The special filehandle for standard output in any package.

DATA

The special filehandle that refers to anything following the __END__ token in the file containing the script. Or, the special filehandle for anything following the __DATA__ token in a required file, as long as you're reading data in the same package __DATA__ was found in.

_ (underscore)

The special filehandle used to cache the information from the last stat, lstat, or file test operator.

4.4.4 Global Special Constants

__END__

Indicates the logical end of your program. Any following text is ignored, but may be read via the DATA filehandle.

__FILE__

Represents the filename at the point in your program where it's used. Not interpolated into strings.

__LINE__

Represents the current line number. Not interpolated into strings.

__PACKAGE__

Represents the current package name at compile time, or undefined if there is no current package. Not interpolated into strings.

4.4.5 Regular Expression Special Variables

For more information on regular expressions, see Section 4.6, "Regular Expressions" later in this chapter.

$digit

Contains the text matched by the corresponding set of parentheses in the last pattern matched. For example, $1 matches whatever was contained in the first set of parentheses in the previous regular expression.

$& $MATCH

The string matched by the last successful pattern match.

$` $PREMATCH

The string preceding whatever was matched by the last successful pattern match.

$' $POSTMATCH

The string following whatever was matched by the last successful pattern match.

$+ $LAST_PAREN_MATCH

The last bracket matched by the last search pattern. This is useful if you don't know which of a set of alternative patterns was matched. For example:

/Version: (.*)|Revision: (.*)/ && ($rev = ___FCKpd___1);

4.4.6 Filehandle Special Variables

Most of these variables only apply when using formats. See Section 4.10, "Formats" later in this chapter.

$|

$OUTPUT_AUTOFLUSH

If set to nonzero, forces an fflush(3) after every write or print on the currently selected output channel.

$%

$FORMAT_PAGE_NUMBER

The current page number of the currently selected output channel.

$=

$FORMAT_LINES_PER_PAGE

The current page length (printable lines) of the currently selected output channel. Default is 60.

$-

$FORMAT_LINES_LEFT

The number of lines left on the page of the currently selected output channel.

$~

$FORMAT_NAME

The name of the current report format for the currently selected output channel. Default is the name of the filehandle.

$^

$FORMAT_TOP_NAME

The name of the current top-of-page format for the currently selected output channel. Default is the name of the filehandle with _TOP appended.

MySQL 8.0密码策略详解:解决ERROR 1819报错的三种实战方案 数据库安全是系统架构中的重要环节,其中密码策略作为基础防护机制,通过预设规则强制用户设置复杂密码,有效防止暴力破解。其原理通常基于密码复杂度检查组件,对长度、字符类型、字典匹配等维度进行校验。在MySQL 8.0中,这一机制通过validate_password组件实现,为数据库账户安全提供了标准化保障。对于开发者而言,理解并妥善处理密码策略,能避免在用户管理、应用部署等场景中因密码不符合要求而导致的运维中断。本文聚焦MySQL 8.0默认启用的密码策略组件,针对常见的ERROR 1819报错,提供创建强密 阅读详情

相关推荐

基于 .NET 平台的开源微服务开发框架,专注于 RPC 通信与服务治理 接口即服务,自动生成 HTTP WebAPI 与 RPC 端点;内置负载均衡、熔断、TCC 分布式事务、链路追踪

基于 .NET 平台的开源微服务开发框架,专注于 RPC 通信与服务治理。接口即服务,自动生成 HTTP WebAPI 与 RPC 端点;内置负载均衡、熔断、TCC 分布式事务、链路追踪;支持 Zookeeper / Nacos / Consul;覆盖 .NET 6~10。

Perl 学习手札之七: special variables

Perl 学习手札之七: special variables perl uses special variable for a number of purpose. default value for function and loops error codes and messages information about the sys...

weixin_33795743的博客 246

TPM2-Startup-学习手册.docx

内容概要:本文深入解析了TPM 2.0中首个必要命令TPM2_Startup的工作机制,涵盖其在芯片初始化中的核心作用、启动类型决策逻辑、内部九个初始化阶段的详细流程,以及DRTM/H-CRTM安全机制的实现原理。文档结合源码(ibmswtpm2-tpm2)与实测报文,系统阐述了Startup如何通过状态校验、locality控制、PCR管理、密码学初始化、DA防护、ACT定时器、NV索引处理等环节,确保TPM在安全可信的状态下启动,并重点剖析了commitNonce重置、DA计时器跨重启续接、ACT减半防攻击等关键安全设计。; 适合人群:对TPM安全芯片感兴趣的零基础或初级开发者,以及从事可信计算、固件安全、系统启动安全相关工作的研发人员。; 使用场景及目标:①理解TPM为何必须以Startup作为第一条命令及其安全意义;②掌握SU_CLEAR、SU_STATE、SU_RESUME、SU_RESTART、SU_RESET等启动类型的决策逻辑与状态迁移;③深入学习DRTM与H-CRTM机制,理解动态信任根的建立过程;④分析DA防护、ACT定时器、有序NV索引等子系统的初始化行为与安全考量;⑤通过实验复现各类启动场景,提升对TPM底层机制的实战理解。; 阅读建议:建议结合文档提供的源码注释、实测报文和动手实验逐步验证,重点关注Startup与Shutdown的配对关系、状态持久化机制(NV)以及各类标志位(如g_DrtmPreStartup、g_StartupLocality3)的作用,注意区分规范定义与具体实现间的差异,并利用附录常量与术语表辅助理解。

MySQL数据库等保2.0合规实战:从核心要求到配置清单

数据库安全是信息系统安全的核心组成部分,尤其在政府、金融等关键行业,它直接关系到数据的保密性、完整性和可用性。其基本原理在于通过身份鉴别、访问控制、安全审计等多层防御机制,构建纵深防护体系。从技术价值看,这不仅是为了满足等保2.0等合规性要求,更是提升系统内在韧性、防范数据泄露与篡改的工程实践。在应用场景上,无论是业务系统的用户数据存储,还是内部的管理后台,数据库都面临着身份冒用、权限滥用、SQL注入等常见威胁。本文聚焦MySQL这一广泛使用的关系型数据库,深入解析其在等保测评中的**安全审计**与**访问

weixin_33924312的博客 450

检索后重排实战:BM25 + 轻量交叉编码器,零 Key 离线可跑(Python 源码)

检索后重排实战包。BM25 召回 + 轻量交叉打分精排,含 nDCG/MRR 评估;无 Key 离线可跑。含样例语料与 smoke。

大唐杯(信科赛)赛道三资料

大唐杯(信科赛)赛道三资料

Linux | Bash Shebang 语法与结构及常见问题排查

……

u013669912的博客 1161

010_专科电子病历(肿瘤_心内等)模板化建设_答辩演示.pptx

010_专科电子病历(肿瘤_心内等)模板化建设_答辩演示

GIS 与农村土地承包数据管理领域的 Python/tkinter 绿色免安装桌面工具,用于 PostGIS/PostgreSQL 入库、MySQL→PG 跨库迁移与数据交换

GIS 与农村土地承包数据管理领域的 Python/tkinter 绿色免安装桌面工具,基于 pyshp、openpyxl、access-parser、pyodbc 读取 Shapefile 矢量坐标(WKT)与属性表、Access MDB 多表数据,按指定份数自动拆分并导出为 Excel 或 SQL,用于 PostGIS/PostgreSQL 入库、MySQL→PG 跨库迁移与数据交换。

国央企创新负责人如何快速识别关键技术成果并推动落地?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

三相电压型PWM整流器PI双闭环控制Matlab仿真

内容概要:本文档系统介绍了三相电压型PWM整流器的PI双闭环控制技术及其在Matlab/Simulink环境下的仿真建模方法,重点阐述了电流内环与电压外环的协同控制机制,旨在实现高功率因数、低电流谐波畸变及稳定的直流母线电压输出。内容涵盖多种典型电力电子变换器的建模与控制策略,包括三相维也纳(Vienna)整流器、双有源桥(DAB)变换器、LLC谐振变换器等,并深入探讨SVPWM调制、滞环电流控制、中点电位平衡、软开关技术、畸变抑制等关键技术。文档提供丰富的仿真模型、Mathcad计算书及参考文献,支持从基础控制结构到高级优化算法(如基于KKT条件的协同最小应力控制)的多层次研究与复现。; 适合人群:电气工程、自动化、电力电子与电力传动等相关专业的高校本科生、研究生,以及从事新能源发电、电动汽车、轨道交通等领域电能变换系统研发的科研人员与工程技术人员;要求具备Matlab/Simulink仿真基础及电力电子、自动控制理论的相关知识背景。; 使用场景及目标:①作为高校课程设计与实验教学的辅助材料,帮助学生掌握PWM整流器双闭环控制系统的设计流程与仿真方法;②支撑科研项目中对高性能整流器控制策略的验证、优化与EI级论文复现;③为工业界在新能源并网、车载充电机、直流配电系统等应用场景中的控制器开发提供仿真依据与参数设计工具;④结合Mathcad计算书实现不同功率等级与电压等级系统的自主建模与参数匹配。; 阅读建议:建议读者按照资源目录顺序循序渐进地学习,先掌握PI双闭环控制的基本架构与仿真调试方法,再逐步拓展至中点平衡控制、电网不平衡工况下的功率调节、软开关优化等高级主题;重点关注“顶级EI复现”案例以提升学术研究深度;推荐结合提供的仿真模型、计算书与参考文献进行对照分析与代码调试,强化理论与实践的融合能力。

单相boost功率因数校正 PFC电路仿真(Simulink仿真实现)

内容概要:本文档全面介绍了“荔枝科研社”这一专注于科研支持的资源共享平台,系统整合了涵盖电力电子、智能优化算法、机器学习、深度学习、图像处理、路径规划、通信技术、信号处理、电力系统管理、元胞自动机模拟、雷达技术、车间调度等多个前沿科技领域的MATLAB/Simulink仿真资源与技术支持。平台不仅提供大量高价值仿真项目实例,如单相/三相功率因数校正(PFC)电路、LLC谐振变换器、双向Buck-Boost储能系统、卡尔曼滤波状态估计、双有源桥DAB变换器等,还配套详尽的仿真模型、计算书、参考文献、说明文档及PPT讲解材料,极大提升了科研复现与工程实践效率。所有资源可通过公众号和百度网盘便捷获取,助力用户快速构建技术能力体系。; 适合人群:面向电气工程、自动化、控制科学与工程、电力电子、通信工程、人工智能、计算机科学及相关交叉学科的硕士博士研究生、高校科研人员、企业研发工程师,尤其适合具备MATLAB/Simulink基础并希望在智能控制、新能源变换、状态估计、优化调度等领域深化研究与应用的专业人士。; 使用场景及目标:①支撑高水平科研论文的仿真复现与算法验证,特别是EI/SCI期刊成果的二次开发;②服务于课程设计、毕业设计、实验教学与课题攻关,提升系统建模与仿真分析能力;③加速工业级项目的原型开发与关键技术预研,如新能源变换器设计、微电网优化调度、无人机路径规划等;④帮助研究人员掌握先进控制策略(如模型预测控制、滑模控制、自适应控制)与现代优化算法(如粒子群、遗传算法、ADMM)的实际应用。; 阅读建议:建议用户结合发布的完整资源目录按需检索,优先选择附带参考文献和说明文档的项目以确保理解深度;在学习过程中应同步下载仿真模型进行实操演练,调试参数并观察响应特性,强化理论与实践结合;对于复杂系统(如多电平变换器、混合储能控制),推荐分模块逐步学习,配合代码注释与设计报告深入剖析其实现逻辑与工程考量。

政府科技管理者如何实现科技成果与产业需求的精准匹配?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

政府科技管理者在推动科技成果转移转化时,如何高效识别具有高转化价值的科研成果.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

基于高斯混合模型GMM的数据生成方法研究(Matlab代码实现)

内容概要:本文围绕Plecs全桥LLC谐振变换器的仿真模型展开,重点研究基于脉冲频率调制(PFM)控制策略的全桥LLC谐振变换器在Plecs或Simulink环境下的建模与仿真方法。内容涵盖系统工作原理、关键参数设计、谐振腔结构分析、软开关实现机制、控制策略实施及仿真结果验证等方面,深入探讨了变换器在不同负载条件下的动态响应特性、效率优化与频率调节范围等关键技术指标。文档提供了完整的仿真模型与代码实现,便于读者复现并开展进一步研究,适用于电力电子系统中高频高效电源的设计与优化。; 适合人群:具备电力电子、自动化或电气工程等相关专业背景,熟悉Plecs/Simulink仿真工具,从事高频电源、DC-DC变换器设计与研究的科研人员、工程师及高校研究生。; 使用场景及目标:①用于全桥LLC谐振变换器的教学演示与科研仿真;②支持对PFM控制下变换器效率、软开关特性、负载调整能力等性能的研究与优化;③为实际工程中高功率密度、高效率电源系统的设计提供理论支撑与仿真验证手段。; 阅读建议:建议读者结合文档中的仿真模型与代码,逐步搭建系统并调试关键参数,重点关注谐振元件(Lr、Cr)的匹配、励磁电感的影响、频率调制范围设置以及轻重载条件下软开关的实现条件,同时可通过对比不同工况下的仿真结果,深入理解LLC变换器的非线性动态特性与优化设计方法。

Unisphere Client/SM/CLI工具

Unisphere Client/SM/CLI工具

上一篇: 如何成为一名黑客
下一篇: File Test Operators
alex_wan
博客等级 码龄20年 2粉丝 5原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值