Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables in perl 1

Status
Not open for further replies.

be12dune09a

Programmer
Nov 17, 2005
24
RO
same text as in variable in php?
 
yes I know :) but whi can I do somthing like
$self = {
NAME => undef,
AGE => undef,
PEERS => [],
};
$ is a scalar not a hash.
 
yes, $self is a reference to an anonymous hash which itself contains an anonymous array: PERRS => []. The use of references allows perl to use complex data structures.

To expand on Tony's answer, %$self or %{$self} is the syntax used to dereference a reference (a hash in this case) so you can get to the data. The reference is just an address in memory where the data can be found, so perl uses the reference to go fetch that particular bit of data from memory, but you have to dereference the reference to actually use the data in the script. The dereference type tells perl what kind of data to expect: a scalar, a hash, an array, or even a sub routine.

I don't beleive PHP has this capability yet, so it will seem strange at first, but it is a powerful tool that will allow you to create data structures that are very useful and versatile.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top