- Perl 6 Deep Dive
- Andrew Shitov
- 266字
- 2021-07-03 00:05:41
Sigils
One of the most difficult things for the newcomers to Perl are sigils. A sigil is a character in front of the name of variables in Perl that denotes the structural type of a variable. For example, $ for scalar values, @ for arrays, and % for hashes.
The problem arises when you access an element of an array or hash. Let's consider the following lines of code as an example in Perl 5 of an array with the first few Fibonacci numbers:
my @fibonacci = (0, 1, 1, 2, 3, 5, 8, 13); print $fibonacci[4];
First, a @fibonacci array is created. The name of the variable includes the @ character as a sigil. In the second line, we access one of the elements of that array and use another sigil, $, this time. This is because a single element of an array is a scalar, and scalars use $ as a sigil. For those who learn Perl, this small change in sigils is a big problem in understanding the basics of the language.
In Perl 6, sigils are unified and are part of the variable names. You do not change it independently, whether you access an element of an array or an array as a whole. The preceding example will look like this in Perl 6:
my @fibonacci = (0, 1, 1, 2, 3, 5, 8, 13); print @fibonacci[4];
In both lines, the same sigil is used for the @fibonacci array and for its @fibonacci[4] element. This approach is much more consistent and easier for a beginner.
- Android應用程序開發與典型案例
- Building a RESTful Web Service with Spring
- HTML5 移動Web開發從入門到精通(微課精編版)
- Responsive Web Design with HTML5 and CSS3
- 跟小海龜學Python
- JavaScript:Moving to ES2015
- Learning Three.js:The JavaScript 3D Library for WebGL
- RabbitMQ Cookbook
- Building Machine Learning Systems with Python(Second Edition)
- 3ds Max印象 電視欄目包裝動畫與特效制作
- Clojure Polymorphism
- After Effects CC案例設計與經典插件(視頻教學版)
- Moodle 3.x Developer's Guide
- Improving your Penetration Testing Skills
- 樹莓派開發從零開始學:超好玩的智能小硬件制作書