Hello Mark, 

> am new to Perl. I'm followig this tutorial,
> 
> http://www.cs.unc.edu/~jbs/resources/perl/perl-basics/variables.html
> 
> and am confused as to why the below shows examples with $ and 
> some with % at the beginning of the statement. When it says, 
> "Perl uses the "percent" symbol and curly braces with respect 
> to the name of an associative array as a whole". Am I to 
> assume that either is fine, when defining associative arrays.? Cheers.

$, @, % and & are called sigils. They preceed variable names.
Together they make a variable. A statement can involve variables,
but doesn't need to do so. Think of a statement as a sentence, and
of variables as a word, then you shuld get the idea ;-)

As for terminology, people often say hash when they mean associative
array.

The sigils denote the type of data you're accessing. So you say
%hash when you mean the whole hash, but $hash{'key'} to access an
individual value in the hash. Likewise, it's @array for a complete
array, but $array[$index] for an element. Note that it's also
legal to say @array[$index1, $index2, $index3] to access several
elements of the array at once.

Things become more confusing when you consider this:

my $badidea; # I am a scalar
my %badidea; # I am a hash

Perl is perfectly willing and able to deal with variables of the same
name when they have different types. It's only people who are confused
by this ;-)

So the sigil does make a difference when defining your variables.

Ganbatte, ne? ;-)

HTH,
Thomas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to