当前位置: 首页 > news >正文

Perl——文件操作

特殊文件句柄

perl提供了6种特殊的文件句柄:

STDIN ,

STDOUT ,

STDERR ,

DATA ,

ARGV,

ARGVOUT。

访问模式

模式描述
< 或 r只读方式打开,将文件指针指向文件头。
> 或 w写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。
>> 或 a写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。
+< 或 r+读写方式打开,将文件指针指向文件头。
+> 或 w+读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。
+>> 或 a+读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。

文件测试

File TestMeaning
-rFile or directory is readable by this (effective) user or group
-wFile or directory is writable by this (effective) user or group
-xFile or directory is executable by this (effective) user or group
-oFile or directory is owned by this (effective) user
-RFile or directory is readable by this real user or group
-WFile or directory is writable by this real user or group
-XFile or directory is executable by this real user or group
-OFile or directory is owned by this real user
-eFile or directory name exists
-zFile exists and has zero size (always false for directories)
-sFile or directory exists and has nonzero size (the value is the size in bytes)
-fEntry is a plain file
-dEntry is a directory
-lEntry is a symbolic link
-SEntry is a socket
-pEntry is a named pipe (a “fifo”)
-bEntry is a block-special file (like a mountable disk)
-cEntry is a character-special file (like an I/O device)
-u

File or directory is setuid

-gFile or directory is setgid
-kFile or directory has the sticky bit set
-tThe filehandle is a TTY (as reported by the isatty() system function; filenames can’t be tested by this test)
-TFile looks like a “text” file
-BFile looks like a “binary” file
-MModification age (measured in days)
-AAccess age (measured in days)
-CInode-modification age (measured in days)
if (-r $filename and -w $filename) {
... }
  • 文件测试操作符没写文件名和文件句柄,则默认文件名保存在$_里
foreach (@lots_of_filenames) {
print "$_ is readable\n" if -r;
}

select

使用select更改默认文件输出句柄

http://www.dtcms.com/a/328002.html

相关文章:

  • 工业相机终极指南:驱动现代智能制造的核心“慧眼”
  • 云原生作业(tomcat)
  • 优选算法 力扣 18. 四数之和 双指针算法的进化 优化时间复杂度 C++ 题解 每日一题
  • Perl——$_
  • Bevy渲染引擎核心技术深度解析:架构、体积雾与Meshlet渲染
  • UE5.3 C++ 动态多播实战总结
  • AtCoder Beginner Contest 418 C-E 题解
  • 数据分析小白训练营:基于python编程语言的Numpy库介绍(第三方库)(上篇)
  • python3 undefined symbol: _Py_LegacyLocaleDetected
  • C语言结构体与内存分配:构建复杂数据结构的基石
  • 【AI驱动的语义通信:突破比特传输的下一代通信范式】
  • Git 常用命令速查表
  • 最终章【1】Epson机器人篇
  • 微服务项目中的注册中心——Nacos配置
  • 【每日一题】Day 1
  • ETCD备份
  • Flask + Vue.js 物联网数字大屏实现方案
  • 学习:JS[9]作用域+函数进阶+深入对象+实例成员和静态成员
  • 为什么神经网络的权重矩阵具有低秩特性?如何理解和解释?
  • [Robotics_py] 机器人运动模型 | `update`函数 | 微积分矩阵
  • 线性代数 · 矩阵 | 最小多项式
  • 有限元方法中的数值技术:行列式、求逆、矩阵方程
  • 企业高性能web服务器(1)
  • 腾讯云服务器账户转移操作详解
  • ip归属地批量查询脚本
  • vue2+elementUI实现园型动态步骤条小组件,带缩放功能
  • ENCOPIM, S.L. 参展 AUTO TECH China 2025 广州国际汽车技术展览会
  • 基于STC8单片机的RTC时钟实现:从原理到实践
  • Cloud Computing(云计算)和Sky Computing(天空计算)
  • 自然语言处理关键库解析和使用方法- FuzzyWuzzy