perl用变量做句柄介绍
时间:2022-12-18 22:19:01
#!/usr/bin/perl -w
use strict;
use warnings;
use FileHandle;
my %fh;
my @array = (1..10);
for(1..5){
open $fh{$_},">$_.txt" or die;
}
for(1..5){
#print $fh{$_} "$_\n"; 此处错误
$fh{$_}->print( "$_\n" );
#为FileHandle里的函数 或 用(my $h = $fh{$_}; print $h "$_\n";)亦可
}
注意:上述错误是由于:<>里面不是简单标量就会被当glob,Perl 支持 <FILEHANDLE> 或者是 <$scalar> .
标签:变量,句柄
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决echarts中饼图标签重叠的问题
2021-10-22 03:33:33
![](https://img.aspxhome.com/file/2023/5/101165_0s.jpg)
python 如何将数据写入本地txt文本文件的实现方法
2021-05-02 14:11:52
Python urllib库的使用指南详解
2021-07-08 20:50:57
详解MySQL数据库--多表查询--内连接,外连接,子查询,相关子查询
2024-01-24 05:20:34
![](https://img.aspxhome.com/file/2023/1/128091_0s.png)
pycharm配置QtDesigner的超详细方法
2022-09-07 13:35:01
![](https://img.aspxhome.com/file/2023/9/131129_0s.png)
基于javascript的Form表单验证
2024-04-10 16:20:03
![](https://img.aspxhome.com/file/2023/3/136703_0s.jpg)
设计英文网站要注意的问题
2011-04-28 11:22:00
Python多模块引用由此引发的相对路径混乱问题
2021-07-11 03:57:10
![](https://img.aspxhome.com/file/2023/8/124388_0s.png)
python出现RuntimeError错误问题及解决
2022-01-01 00:58:08
![](https://img.aspxhome.com/file/2023/6/102906_0s.png)
Python MySQLdb 使用utf-8 编码插入中文数据问题
2023-07-31 11:04:13
Python爬虫设置代理IP的方法(爬虫技巧)
2023-08-08 22:05:36
MySQL视图的概念和操作函数详解
2024-01-24 15:27:22
jQuery页面滚动浮动层智能定位实例代码
2024-04-22 22:22:16
mysql 5.7.17 winx64安装配置方法图文教程
2024-01-25 08:23:38
基于javascript实现全国省市二级联动下拉选择菜单
2023-09-14 06:08:52
![](https://img.aspxhome.com/file/2023/3/56303_0s.jpg)
PHP htmlentities()函数用法讲解
2023-06-04 14:47:30
![](https://img.aspxhome.com/file/2023/3/55383_0s.png)
微信 java 实现js-sdk 图片上传下载完整流程
2024-04-29 14:08:03
微信小程序 picker-view 组件详解及简单实例
2024-04-19 09:44:13
![](https://img.aspxhome.com/file/2023/2/136402_0s.jpg)
python+opencv 读取文件夹下的所有图像并批量保存ROI的方法
2021-02-23 13:07:23
深入理解Sql Server中的表扫描
2024-01-27 09:05:33
![](https://img.aspxhome.com/file/2023/6/102006_0s.png)