当前位置: 首页 > 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.lryc.cn/news/618376.html

相关文章:

  • 导入文件到iPhone实现
  • 【网站深入seo方法】
  • Rocky Linux 10 部署 Kafka 集群
  • 工业相机镜头选型
  • 云计算核心技术
  • iPhone 17 Pro 为何被指像充电宝?
  • Stereolabs ZED相机 选型指南:双目 / 单目、短距 / 长距,如何为机器人视觉系统匹配最优方案?
  • 力扣11:盛水最多的容器
  • 深入C#异步编程基石:BeginInvoke与EndInvoke全解析
  • 使用ceph-deploy安装和配置RADOS Gateway (RGW)并使用S3访问集群
  • 串口超时参数深度解析:ReadTotalTimeoutMultiplier、ReadIntervalTimeout等
  • JVM宝典
  • 在IDEA中设置SQL解析作用域解决无法解析表的问题(详细图解)
  • Docker部署kafka实操+Java中访问
  • 【KO】大厂常见问题
  • damn the jvm again(2)
  • DDIA第五章:无主复制(去中心化复制)详解
  • 华为发布AI推理新技术,降低对HBM内存依赖
  • 阿里云国际DDoS高防:添加网站配置指南
  • LabVIEW菜单操控
  • 【USRP】基于LabVIEW的BPSK、QPSK,文本,图片
  • 区块链技术原理(7)-安全问题
  • C++少儿编程(二十二)—条件结构
  • 云原生作业(nginx)
  • QT(概述、基础函数、界面类、信号和槽)
  • Linux 服务器,安装mqtt服务
  • Linux 系统下 VS Code 降级至 1.85 版本教程:通过历史版本网站解决兼容性问题
  • 从零开始手搓一个GPT大语言模型:从理论到实践的完整指南(一)
  • Linux性能监控
  • Qt Charts 深度解析与实战指南