Linux Today: Linux News On Internet Time.
Search Linux Today
Linux News Sections:  Developer -  High Performance -  Infrastructure -  IT Management -  Security -  Storage -
Linux Today Navigation
LT Home
Contribute
Contribute
Link to Us
Linux Jobs


Top White Papers

More on LinuxToday


Linux Magazine: Getting Better References Through Perl

May 20, 2000, 20:07 (1 Talkback[s])
(Other stories by Randal L. Schwartz)

"You need references. Everybody programming in Perl does, since they are one of the basics of the language. A bit like C's pointers, references can be used to refer to all sorts of other things, including scalars, arrays, hashes, filehandles, typeglobs, subroutines, and synthetic data structures. If C calculates addresses and dereferences pointers with & and *, respectively, Perl does much the same with \ and $."

"Why use references? First, they go great with subroutine calls. The usual way to pass an array or hash between a subroutine and its caller involves pushing around all the values of the array or hash. You can get the same or better results instead by passing just the single reference to the array or hash."

"Also, references are necessary for complex data structures. The values of arrays and hashes must be scalars, so there's no direct way to make hashes of hashes. However, references have the syntax of scalars, so you can make arrays of references to arrays of...."

Complete Story

Related Stories: