为什么 Perl 变量需要以 $、%、@(符号)开头? [英] Why do Perl variables need to start with $, %,@ (sigils)?

查看:21
本文介绍了为什么 Perl 变量需要以 $、%、@(符号)开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 Perl 变量需要以不同的字符(符号)开头?

Why do Perl variables need to start with different characters (sigils)?

  • 标量变量以 $

哈希以 %

数组以@

他们为什么这样?

推荐答案

当我开始使用 Perl 时,有人向我解释选择这些字符是因为:

When I started out using Perl it was explained to me that these characters were chosen because:

  • $ 看起来有点像一个 's' 所以它是 scalars,
  • @ 中间有一个a",所以它是用于 a 射线,和
  • % 用于散列,因为它看起来像一个被斜杠分隔的键值对.
  • $ looked a bit like an 's' so that was for scalars,
  • @ has an 'a' in the middle so that was for arrays, and
  • % was for hashes because it looked like a key-value pair divided by a slash.

这篇关于为什么 Perl 变量需要以 $、%、@(符号)开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆