当前位置:网站首页>Introduction to Perl (IX) quotation
Introduction to Perl (IX) quotation
2022-07-28 06:28:00 【Shilu building】
A reference can be understood as a pointer , Play a directional role , Can point to scalar 、 Array 、 Hash tables and even sub functions .
One 、 Create reference
Reference is a scalar type , Prefix the referenced variable name with “\”, It means that the variable is referenced , Examples are as follows :
$scalarref = \$foo; # Scalar variable reference
$arrayref = \@ARGV; # References to arrays
$hashref = \%ENV; # Hash reference
$coderef = \&handler; # Sub function reference Multi dimensional arrays can be constructed by reference , Use here "[ ]" Define an anonymous array , If you refer to the array assignment method to use “()”, Then what you get is not a quote , It's the length of the returned array .
my $aref = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]Except for anonymous arrays , And anonymous hash table , Use “{ }” To define .
$href= { APR =>4, AUG =>8 };Sub function reference format : \&.
Call reference function format : & + Created reference name .
#!/usr/bin/perl
# Function definition
sub PrintHash{
my (%hash) = @_;
foreach $item (%hash){
print " Elements : $item\n";
}
}
%hash = ('name' => 'it', 'age' => 3);
# Create a reference to a function
$cref = \&PrintHash;
# Use references to call functions
&$cref(%hash);The operation results are as follows :
Elements : age
Elements : 3
Elements : name
Elements : itTwo 、 Dereference
Dereference can be used according to different types $, @ or % + Variable name to cancel , Scalar $, Array with @, Hash with %.
#!/usr/bin/perl
$var = 10; # $r quote $var Scalar
$r = \$var; # Output locally stored $r Variable value
print "$var by : ", $$r, "\n";
@var = (1, 2, 3); # $r quote @var Array
$r = \@var; # Output locally stored $r Variable value
print "@var by : ", @$r, "\n";
%var = ('key1' => 10, 'key2' => 20); # $r quote %var Hash
$r = \%var; # Output locally stored $r Variable value
print %var ," by : ", %$r, "\n";
sub add {
$count = @_[0] + @_[1];
}
$value = \&add;
print add(1,2), "=" &$value "\n"; It should be noted here that neither hash nor subfunction can be placed in double quotation marks ” “ in ,print You can use commas between strings of ”,“ Separate . The running result is :
10 by : 10
1 2 3 by : 123
key110key220 by : key110key220
3=3When you are not sure what type the reference is, you can use ref To judge .
#!/usr/bin/perl
$var = 10;
$r = \$var;
print "r The type of reference : ", ref($r), "\n";
@var = (1, 2, 3);
$r = \@var;
print "r The type of reference : ", ref($r), "\n";
%var = ('key1' => 10, 'key2' => 20);
$r = \%var;
print "r The type of reference : ", ref($r), "\n";The operation results are as follows :
r The type of reference : SCALAR
r The type of reference : ARRAY
r The type of reference : HASH边栏推荐
- Varistor design parameters and classic circuit recording hardware learning notes 5
- Photovoltaic power generation system MPPT maximum power point tracking
- How to use the bit error meter?
- Why should fluke dsx2-5000 network cable tester be calibrated once a year?
- Low power design isolation cell
- Trouble encountered in cable testing -- a case study of a manufacturer?
- 福禄克DSX2-5000 网络线缆测试仪为什么每年都要校准一次?
- PT 基于Multi Voltage的Physical Aware
- The short jumper dsx-8000 test is normal, but the dsx-5000 test has no length display?
- 机器学习笔记 5 —— Logistic Regression
猜你喜欢

mixup_ratio

Efficient Net_ V2

How to view the transfer function of the module directly built by Simulink

ICC2(三)Clock Tree Synthesis

What is the AEM testpro cv100 and fluke dsx-8000 of category 8 network cable tester?

Bag of tricks training convolution network skills

Shuffle Net_ v1-shuffle_ v2

IMS-FACNN(Improved Multi-Scale Convolution Neural Network integrated with a Feature Attention Mecha

EMC experiment practical case ESD electrostatic experiment

set_ clock_ groups
随机推荐
Briefly introduce EMD decomposition, Hilbert transform and spectral method
A NOVEL DEEP PARALLEL TIME-SERIES RELATION NETWORK FOR FAULT DIAGNOSIS
论文神器 VS Code + LaTex + LaTex Workshop
Exploration of Clickhouse aggregation internal mechanism of aggregation
Learning notes of hardware circuit design 1 -- temperature rise design
Precautions for EMI design of switching power supply circuit in layout process
Cronbach’s α? Kmo coefficient? Factor load? The most understandable course of questionnaire reliability and validity analysis in history!!! (SPSS and AMOS)
How can fluke dsx2-5000 and dsx2-8000 modules find the calibration expiration date?
What happens when MySQL tables change from compressed tables to ordinary tables
How does fluke dtx-1800 test cat7 network cable?
ICC2分析时序的神器 analyze_design_violations
机器学习笔记 5 —— Logistic Regression
雷达成像 Matlab 仿真 3 —— 多目标检测
浅谈FLUKE光缆认证?何为CFP?何为OFP?
PyTorch 学习笔记 4 —— 自动计算梯度下降 AUTOGRAD
Web scrolling subtitles (marquee example)
PyTorch 学习笔记
Matlab simulation of radar imaging 4 - range resolution analysis
【服务器使用记录】通过跳板机登录远程服务器并进行文件传输
Surge impact immunity experiment (surge) -emc series Hardware Design Notes 6