T
Torch
I know that
$ is used to declare variables
@ is used to declare arrays
% is used to declare ???????
$ is used to declare variables
@ is used to declare arrays
% is used to declare ???????
I know that
$ is used to declare variables
@ is used to declare arrays
% is used to declare ???????
To be more precise: scalar variableTorch said:I know that
$ is used to declare variables
To be more precise: array variable@ is used to declare arrays
Hash variables.% is used to declare ???????
Jürgen Exner said:You can think of hashes in two ways. They are like arrays, except that they
allow arbitrary scalar values as indices.
Jürgen Exner said:To be more precise: scalar variable
To be more precise: array variable
Hash variables.
Actually, those characters don't declare variables but they indicate the
type of a variable, in a declarations as well as in any application of the
variable. They are an integral part of the variable name itself.
Ben said:Arbitrary *string* values.
Josef =?iso-8859-1?Q?M=F6llers?= said:Says who?
The camel book says: "... a scalar always contains a single value. This
value may be a number, a string, or a reference to another piece of
data. Or, there might even be no value at all, in which case the scalar
is said to be undefined."
Yes.
But, although it also says "As we said earlier, a hash is just a funny
kind of array in which you look values up using key strings instead of
numbers.", let's give it a try:
my %hash = ();
$hash{0x10} = "Sixteen";
print $hash{16}, "\n";
-> Sixteen
my %hash = ();
$hash{undef} = "Not defined";
print $hash{undef}, "\n";
-> Not defined
$a = 1;
$b = \$a;
my %hash = ();
$hash{$b} = "Reference to a";
print $hash{\$a}, "\n";
-> Reference to a
So, in all aspects, "scalar" is perfectly ok.
Ben said:works. Now try
use strict;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.