Slick wrote:
Just clarification.  At this time I have not written any of my code
(dont' know where to begin yet, however the website that I am looking
at perl.begin.org seems to have diffrent methods for one item.  I have
seen @ for arrays written like this:   @myarray ,but I have also seen
an array per the perl.begin.org writting like:
   $primes[$num_primes].  Are they both the same? Because it would be
easier in my opinion to write:

@myarray = 4;
instead of writing this: $primes[$num_primes] = 2;
Am I mising something, or are these two things interchangable?

In Perl a '$' in front of a variable name indicates a scalar value so an array name (or a hash name) with a '$' in front of it indicates that you are accessing a single scalar value from an array (or hash.) So ...

@array

Indicates a complete array of zero or more scalar elements.  And ...

$array[ EXPRESSION ]

Indicates a single scalar value from that array, where EXPRESSION is any valid Perl expression that is evaluated as an integer to determine which element to access. Then there is also ...

@array[ LIST ]

Indicates that LIST is evaluated as a list of integers to determine the list of elements to access. This is called an array slice.

The same idea works for hashes:

%hash

$hash{ EXPRESSION }

@hash{ LIST }



perldoc perldata



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to