This is a discussion on Re: [offtopic] perl newbie frustrated - modperl ; um, lemme clarify a bit there-- On 7/13/06, will trillich wrote: > () is a LIST of values, perfect for plopping into an array: > > @a = (qw/one two three/, 22/7, pi()) a list is a series of values. ...
um, lemme clarify a bit there--
On 7/13/06, will trillichwrote:
> () is a LIST of values, perfect for plopping into an array:
>
> @a = (qw/one two three/, 22/7, pi())
a list is a series of values. an array is a place-holder for a series of values.
(1..99,'a'..'z',@stuff,qw/plus lots more/) is a list
@vals is an array that can have lots of items, usable as a list
> the way you pick out elements of an array is by using the [brackets]:
>
> print $a[two], $a[pi()].
wow, clear as mud, eh? sheesh!
if you happen to have a "sub two{}" that returned 2, and pi() returned
3.1415 then you'd get array entries 2 and 3 with that statement.
obvsiouly i have hashes on the brain, but i think i wormed my way out
of this one... sorta.
> so the perl wonks figured it would be cool to have insta-arrays at
> your fingertips by using the brackets without an array name:
>
> $x = [$val,@array,&function];
> print $x->[1],$x->[-1];
>
> usually this type of thing is more usefully applied to hashes:
>
> %x = (one=>1, nine=>9, fifty=>50);
> $x = {one=>1, two=>2, structure=>{one_one=>1.1,nine_two=>9.2},more=>'yup'}
and
$x = { %$x, more=>'stuff here'};
$x->{another}='some value';
$x->{structure}{e}=2.71828;
> print $x->{structure}{one_one};
>
> see man perlref or man perlreftut for the full scoop.
--
will trillich
"The great enemy of clear language is insincerity." -- Eric Arthur
Blair (George Orwell)