欢迎来到天天文库
浏览记录
ID:21240594
大小:394.00 KB
页数:57页
时间:2018-10-20
《perl_13_references》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter13-ReferencesOutline13.1Introduction13.2References13.3ReferencestoNonscalars13.4AnonymousStructures13.5Closures13.6ReferencesasFunctionArguments13.7NestedDataStructures13.8GarbageCollectionandCircularReferences13.9SymbolicReferences13.10Typegl
2、obs13.11ReferencingFilehandles13.12UsesforReferences13.13InternetandWorldWideWebResources13.2ReferencesReferenceIndirectlypointstovalueScalarsthattellprogramwheretofindanothervalueHardReferencesReferdirectlytoavalueinmemoryNotavariableUnarybackslashoperato
3、r()SymbolicReferencesSoftreferencesHoldthenameofthevariabletowhichtheyrefertoFig13_01.pl1#!/usr/bin/perl2#Fig.13.1:fig13_01.pl3#Demonstratescreatinganddereferencingareference.45usestrict;6usewarnings;78my$variable=10;9my$reference=$variable;1011print("$var
4、iable=$variable");12print("$reference=$reference");13print("$$reference=$$reference");14$variable++;15print("$variable=$variable");16print("$reference=$reference");17print("$$reference=$$reference");18$$reference++;19print("$variable=$vari
5、able");20print("$reference=$reference");21print("$$reference=$$reference");$referenceisahardreferencetoscalar$variablePrintsthevaluethatthereferencepointstoAdds1to$variablewillalsoaffectthevalue$referencepointstoAdds1to$$reference,willalsochangetheva
6、lueof$variablePrintsthevalueofthereferencePrintsthevalueof$variableFig13_01.plProgramOutput$variable=10$reference=SCALAR(0x8a31018)$$reference=10$variable=11$reference=SCALAR(0x8a31018)$$reference=11$variable=12$reference=SCALAR(0x8a31018)$$reference=1213.3Re
7、ferencestoNonscalarsNonscalarReferencesSamesyntaxasaareferencetoascalarNestedreferencesTwowaysofdereferencingArrowoperator(->)Witharrays$$reference[element]$reference->[element]@$referenceisusedtoaccessthewholearray13.3ReferencestoNonscalarsWithhashes$$refere
8、nce{‘key’}$reference->{‘key’}%$referenceisusedtoaccessthewholehashDirectdereferencingWithfunctions&$function(arguments)$function->(arguments)Fig13_02.pl1#!/usr/bin/perl2#Fig.13.2:fig13_02
此文档下载收益归作者所有
点击更多查看相关文章~~