Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Perl Learning - 3 (A

Perl Learning - 3 (A

作者头像
py3study
发布于 2020-01-10 03:39:19
发布于 2020-01-10 03:39:19
1.1K0
举报
文章被收录于专栏:python3python3

List & Array

While scalar is single value, list is a list of scalars in order. Every element of a list is a dependant scalar, it can be number or characters.

Array is the variable of list, list is the values of array. In Perl array and list are almost the same meaning: a list of scarlars.

Every element of array is kept with its index, starting from [0].

$fred[0]="yabba"; $fred[1]="dabba"; $fred[2]="doo";

Arrays and Scalars have different namespaces, such as $fred[0] and $fred can be used at the same time, Perl won't be confused, but maybe the maintainer will, so don't play Perl like that. We can do whatever to array elements like we do to a scalar.

print $fred[0]; $fred[2]="didley"; print $fred[$number-1];

Like the last example, we can use variable and expression in array's index. Element without a value will be undef.

Array can grow its length automatically if you give values to a certain index.

$rocks[0]='bedrock'; $rocks[1]='slate'; $rocks[2]='lava'; $rocks[3]='crushed rock'; $rocks[99]='schist';      # 95 undef elements created!

There are two ways to directly get the last element of an array:

$rocks[$#rocks]='hard rock'; $rocks[-1]='hard rock';

$#rocks is the index of last element, both above ways are correct, but [-1] is more popular ^_^

list/array can be writen in ( ), split by ',' between neighbour elements.

(1, 2, 3) (1, 2, 3,) # same as above ()  # empty list, containing 0 element (1 .. 100) # a list of 100 int (5 .. 1) # empty list, .. is order sensitive (2, 2 .. 6, 10, 12 ) # same as (0, 2, 3, 4, 5, 6, 10, 12)

("fred", "barney", "betty", "milma", "dino") # list of characters

($m .. $n) (0 .. $#rocks) ($m, 17) # two values ($m+$0, $p+$q) # two values

The last 4 examples shows element can be variable and/or expression too.

List of characters are very common, qw was designed for this. qw means 'quotes words', it works as a piar of ' .

qw(fred barney betty wilma dino) # same as ('fred', 'barney', 'betty', 'milma', 'dino')

qw will ignore the whitespace (spaces, tabs newlines), and the ( ) can be other symbols.

qw ! fred barney betty wilma dino ! qw# fred barney betty wilma dino # # like comments qw( fred barney betty wilma dino ) qw{ fred barney betty wilma dino } qw[ fred barney betty wilma dino ] qw< fred barney betty wilma dino >

qw{ /usr/dict/words /home/rootbeer/.ispell_english # a good way representing Unix paths }

Like scalar, we can give values to list.

($fred, $barney, $dino)=("flintstone", "rubble", undef); ($fred,$barney)=($barney,$fred); # a simple way to replace values of varables ($betty[0],$betty[1])=($betty[1],$betty[0]);

($fred,$barney) = qw<flintstone rubble slate granite>; # slate and granite will be ignored ($wilma,$dino) = qw[flintstone];   # $dino is undef

We can use @ to give values to an array.

@rocks=qw/bedrock slate lava/; @tiny=();   # empty list @stuff=(@giant, undef, @giant);

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Cisco Catalyst 3750 配置自动备份
交换机的配置信息十分关键,如果可以对这类信息进行自动备份并且进行版本控制就可以有效降低生产风险
franket
2021/08/12
7840
memcahced perl 测试
  'urllist' => [q[http://mirrors.ustc.edu.cn/CPAN/]],
星哥玩云
2022/07/03
1.1K0
脚本分享—将GenBank格式的文件转换为GFF3格式
小编欢乐豆又放出一个珍藏多年的脚本,2749 行的长度,长到已经难以用 GPT 解读啦,不过用起来还是很方便的!这个 perl 脚本用于将 GenBank 格式的文件转换为 GFF3 格式。
用户1075469
2024/01/26
4370
脚本分享—将GenBank格式的文件转换为GFF3格式
在windows上搭建镜像yum站的方法(附bat脚本)
惨绿少年
2017/12/27
2.9K0
在windows上搭建镜像yum站的方法(附bat脚本)
容器技术|Docker三剑客之docker-machine
ocker-machine就是docker公司官方提出的,用于在各种平台上快速创建具有docker服务的虚拟机的技术,甚至可以通过指定driver来定制虚拟机的实现原理(一般是virtualbox)。
民工哥
2020/09/16
5920
容器技术|Docker三剑客之docker-machine
技术分享 | MySQL Test 初探
MySQL Test 是 MySQL 发行版本中集成 all-in-one 测试框架,用于做 mysql 服务的单元,回归和一致性测试,并提供了运行单元测试和创建新单元测试的工具。
爱可生开源社区
2020/04/08
1.5K0
brew安装nvm、node及配置
然后添加这一段到 ~/.bash_profile 或者 ~/.zshrc(没有就创建):
阿超
2023/07/08
1.9K0
centos国内源总结
有时候centos使用yum命令的时候软件下载速度会很慢,还好国内有很多镜像站供大家选择,在此博主为大家总结了一些centos国内镜像站,如果你需要下载centos的iso文件或者相关软件,可以到以下网站下载,速度相当快!
老高的技术博客
2022/12/27
1.4K0
Dockerfile实例
Debian软件包的包名叫 deb ,类似于rpm包; deb 包的管理方式有 dpkg 、apt 两种方式deb包。对于软件管理有dpkg apt两种:
Alone-林
2023/03/17
4850
Dockerfile实例
日志服务器(3)
设置mysql密码 [root@h105 mysql]# /etc/init.d/mysql start Starting MySQL (Percona Server)... [ OK ] [root@h105 mysql]# mysqladmin -uroot password 'mysql' Warning: Using a password on the command line interface can be insecure. [root@
franket
2021/10/19
5470
perl dancer 基础6
安装Expect 可以使用下面方法安装 cpanm cpanm Expect CPAN shell perl -MCPAN -e shell install Expect 或直接在cpan中进行安装 cpan[2]> install Expect CPAN: Storable loaded ok (v2.20) CPAN: LWP::UserAgent loaded ok (v5.833) CPAN: Time::HiRes loaded ok (v1.9721) Fetching with LWP:
franket
2022/03/25
2.1K0
中国开源镜像
China    Alibaba Cloud Computing    http://mirrors.aliyun.com/centos/ 阿里巴巴         China    Beijing Institute of Technology    http://mirror.bit.edu.cn/centos/ 北京理工大学         China    Beijing Teletron Telecom Engineering    http://mirrors.btte.net/centos/     北京电子电信工程     China    BitComm Ltd.    http://mirrors.pubyun.com/centos/ 公云         China    CDS China    http://mirrors.yun-idc.com/centos/    ftp://mirrors.yun-idc.com/centos/    rsync://mirrors.yun-idc.com/centos/ 首都在线 China    China University of Geosciences    http://mirrors.cug.edu.cn/centos/         中国地质大学 China    Dalian Neusoft University of Information    http://mirrors.neusoft.edu.cn/centos/    ftp://mirrors.neusoft.edu.cn/centos/     东软 China    Grand Cloud    http://mirrors.grandcloud.cn/centos/     盛大云     China    Huazhong University of Science and Technology    http://mirrors.hust.edu.cn/centos/        rsync://mirrors.hust.edu.cn/centos/ 华中科技大学 China    NetEase    http://mirrors.163.com/centos/     网易     China    Northeastern University, Shenyang Liaoni    http://mirror.neu.edu.cn/centos/ 东北大学         China    Qiming College of Huazhong University of Science and Technology    http://mirrors.hustunique.com/centos/        rsync://mirrors.hustunique.com/centos/ 华中科技大学 China    Sohu Inc, Beijing P.R. China    http://mirrors.sohu.com/centos/         搜狐 China    The Linux open source community mirror    http://mirrors.skyshe.cn/centos/        rsync://mirrors.skyshe.cn/centos/ 中国linux开源社团 China    University of Science and Tech of China    http://centos.ustc.edu.cn/centos/ 中国科技大学         China - Hong Kong     Web Services Ltd.    http://mirror.vpshosting.com.hk/pub/linux/centos/    ftp://mirror.vpshosting.com.hk/pub/linux/centos/     Hong Kong    01LINK NETWORK SERVICES LIMITED    http://centos.01link.hk/    ftp://centos.01link.hk/    rsync://centos.01link.hk/centos/ Hong Kong    CommuniLink Internet Limited    http://centos.communilink.net/    ftp://centos.communilink.net/centos/     Hong Kong    i-System Technology Limited    http://centos.uhost.h
三杯水Plus
2018/11/14
3.8K1
官方源、镜像源汇总
部分摘录自:http://blog.csdn.net/wh211212/article/details/53593057
惨绿少年
2018/07/31
6.1K0
官方源、镜像源汇总
【CTFd】靶场安装与配置(Docker一键配置版)
【CTFd】靶场安装与配置这由于上一次的配置有点小问题,主要是Whale插件不再支持CTFd3.x版本,于是找了个新的插件使用 并且找到了更好的解决方式,不用那么麻烦配环境了 CTFd-Whale最新维护仓库 这次我采用Docker一键部署,并且稍加改动添加了中文包 成果图
正汰
2024/01/16
1.1K0
【CTFd】靶场安装与配置(Docker一键配置版)
install_driver(mysql) failed
    安装好了mysql监控神器innotop,正得意,innotoop不可用,其错误提示为install_driver(mysql) failed: Can't load '/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.15: cannot open shared object  file:...经查原有又是DBD惹的祸,这个问题已经发生过好几次了。 1、故障现象 [root@dbsrv1 ~]# cat /etc/issue CentOS release 5.11 (Final) Kernel \r on an \m [root@dbsrv1 ~]# innotop localhost PROCESSLIST_NO_IS: install_driver(mysql) failed: Can't load '/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.15: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230. at (eval 504) line 3 Compilation failed in require at (eval 504) line 3. Perhaps a required shared library or dll isn't installed where expected  at /usr/bin/innotop line 7601 2、安装perl-DBD-MySQL [root@dbsrv1 ~]# yum install perl-DBD-MySQL Loaded plugins: fastestmirror, security Repository base is listed more than once in the configuration Repository updates is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository centosplus is listed more than once in the configuration Repository contrib is listed more than once in the configuration Loading mirror speeds from cached hostfile  * base: mirrors.163.com  * epel: mirrors.ustc.edu.cn  * extras: mirrors.skyshe.cn  * updates: mirrors.pubyun.com Setting up Install Process Package perl-DBD-MySQL-3.0007-2.el5.x86_64 already installed and latest version Nothing to do ###上面描述已经perl-DBD-MySQL已经安装,且为最新的版本 [root@dbsrv1 yum.repos.d]# rpm -qa |grep -i dbd perl-DBD-MySQL-3.0007-2.el5 ###首先先卸载perl-DBD-MySQL,然后再次使用yum安装 [root@dbsrv1 yum.repos.d]# rpm -e --nodeps perl-DBD-MySQL-3.0007-2.el5 [root@dbsrv1 yum.repos.d]# rpm -qa |grep -i dbd [root@dbsrv1 yum.repos.d]# yum install perl-DBD-MySQL Loaded plugins: fastestmirror, security Repository base is listed more than once in the configuration Reposit
Leshami
2018/08/13
7620
厦门大学不再提供R语言镜像
深感遗憾,我以前的教程还特意选择了他,比如下面的安装最新版R语言: sudo vi /etc/apt/sources.list# deb http://mirrors.xmu.edu.cn/CRAN/bin/linux/ubuntu/ xenial/sudo apt-get updatesudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9sudo apt-get updatesudo apt-get in
生信技能树
2018/03/09
1.5K0
厦门大学不再提供R语言镜像
CentOS 6.5下源码安装GCC-4.8.2安装笔记整理
经历了两天的虐心,写了两篇不敢发表的gcc4.8.2安装笔记,终于成功用源码安装最新的gcc-4.8.2,虽然最初只是为了试一试c++11的几个性能,但是后来不断遇到的问题和搜索中发现的这些问题在大家安装过程中的普遍存在,决心把它写下来和大家共享,鄙人也是个菜鸟,有什么说的不对的地方希望大家予以指正,不胜感激:
知忆
2021/06/07
1.3K0
日志分析工具Awstats实战之Nginx篇
前言: Awstats 是在 SourceForge 上发展很快的一个基于 Perl 的 WEB 日志分析工具,一个充分的日志分析让 Awstats 显示您下列资料: 访问次数、独特访客人数, 访问时间和上次访问, 使用者认证、最近认证的访问, 每周的高峰时间(页数,点击率,每小时和一周的千字节), 域名/国家的主机访客(页数,点击率,字节,269域名/国家检测, geoip 检测), 主机名单,最近访问和未解析的 IP 地址名单 大多数看过的进出页面, 档案类型, 网站压缩统计表(mod_gzip 或者 mod_deflate), 使用的操作系统 (每个操作系统的页数,点击率 ,字节, 35 OS detected), 使用的浏览器, 机器人访问(检测 319 个机器人), 蠕虫攻击 (5 个蠕虫家族), 搜索引擎,利用关键词检索找到你的地址, HTTP 协议错误(最近查阅没有找到的页面), 其他基于 URL 的个性报导,链接参数, 涉及综合行销领域目的. 贵网站被加入"最喜爱的书签".次数. 屏幕大小(需要在索引页补充一些 HTML 标签). 浏览器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader. 负载平衡服务器比率集群报告.
星哥玩云
2022/06/11
1.2K0
日志分析工具Awstats实战之Nginx篇
ubuntu更换源
源就是用来apt-get下载软件的网址 不同的网络状况连接以下源的速度不同, 建议在添加前手动验证以下源的连接速度(ping下就行),选择最快的源可以节省大批下载时间。 首先备份源列表: sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup 而后用gedit或其他编辑器打开: sudo gedit /etc/apt/sources.list 从下面列表中选择合适的源,替换掉文件中所有的内容,保存编辑好的文件: 注意:一定要选对版本 然后,刷新列表: sudo apt-get update 注意:一定要执行刷新 源列表
用户1148523
2019/05/27
6.4K0
Python3.7开发环境安装
之前讲Python3(3.6.x)基础的过程中,Python3.7发布了,当时说很多第三方库没更新全,现在可以安装了。
逸鹏
2018/08/14
1.9K0
相关推荐
Cisco Catalyst 3750 配置自动备份
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文