/ Published in: HTML
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<pre> Tiffany S. ([email protected]) wrote: : What do the symbols => and -> mean? I can find them used in scripts, : but I can't find them explained in either books or online. Without even knowing the language it's hard to give a correct answer. But I'll guess your using perl. First, if indeed perl is the language, then the answer most certainly is available online, you just need to know what to read. If you have perl installed then type perldoc perlsyn perldoc perlop If you don't have perl installed then type the above into google instead, or google something like "perl" "operators" Anyway, in perl, => is a special type of comma. It's used like a comma but the thing on the left is automatically quoted (basically). so ("one","two") is similar to (one=>"two") And -> means "points to". It's taken from C notation and has a similarish meaning. If, instead of a plain old variable that contains a value, you instead have a variable that _references_ another variable, then you can't get the value directly because it isn't kept "in" the variable. Instead the variable "points to" where the value is kept. Read the doc for details. so you will see things like $x[0] # first element of an array called "x" $x->[0] # first element of an array, but the array is _not_ called # "x". Instead the array is kept somewhere else, and # the variable "x" _points to_ where the array is being # kept. <hr> Tiffany S. wrote: > What is the explanation of the => and the -> operands? I've run > across them, but can't find anything about them in tutorials or > reference manuals. => can be used in place of a comma, and is commonly used to separate key/value pairs when creating a hash. my %hash = (dog, 'bark', cat, 'meow', cow, 'moo', pig, 'oink' ); can be written as: my %hash = (dog => 'bark', cat => 'meow', cow => 'moo', pig => 'oink' ); The => simply makes it easier to read. If, instead, I had written: my $hash = {dog => 'bark', cat => 'meow', cow => 'moo', pig => 'oink' }; (note the curly brackets instead of parentheses) then $hash would contain a reference to a hash. I would have to dereference the hash to access any of the values for a given key. I could print $$hash{dog}; or I could print $hash->{dog}; If you are not familiar with references, look here: http://perldoc.perl.org/perlreftut.html </pre>
URL: http://groups.google.com/group/comp.infosystems.www.authoring.cgi