@{$var1{$var2}}
Hi,
I'm reading a program written in perl and I read this statement
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: @{$var1{$var2}}
--0015175cf75822e6f604a652455e
Content-Type: text/plain; charset=UTF-8
On Wed, Jun 22, 2011 at 6:44 PM, josanabr <john.sanabria [at] gmail.com> wrote:
> Hi,
>
> I'm reading a program written in perl and I read this statement
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
> For additional commands, e-mail: beginners-help [at] perl.org
> http://learn.perl.org/
>
>
>
Without any more information I would have to say good, and what do you want
form the list? (it really does help if you formulate a question and ask what
it is that you want to know ;-)
I suspect hat you are wondering what this means right?
Lets dissect this a little:
Lets take the inner most thing ($var2) this is obviously a scalar (or a
reference to another variable (I'll explain why I am betting it is a scalar
in a bit))
Then we see the following: $var1{...} this is the way one accesses a
variable in a hash based on the key (the thing that goes between those
brackets). Usually the keys used in a has are scalars of course there is
nothing stopping anyone from using complex data structures as a key but it
is performance wise not the smartest thing to do.
The last bit then [at] {...} basically says treat what is in side the brackets
as an array (which is what one would do if one is expecting an array
reference to be returned from $var1's value associated with key $var2.
So what would the data structure look like?
{
"Hash key 1" => \[
'Array value 1',
'Array value 2',
...
],
"Hash key 2" => \[
'Array value 1',
'Array value 2',
...
],
...
}
Or in text form: $var1 is an hash containing keys associated with values
which are references to arrays.
I hope that explains things a little bit. :-)
Regards,
Rob
--0015175cf75822e6f604a652455e--
Re: @{$var1{$var2}}
On 6/22/11 Wed Jun 22, 2011 9:44 AM, "josanabr" <john.sanabria [at] gmail.com>
scribbled:
> Hi,
>
> I'm reading a program written in perl and I read this statement
It is best to put all of your post in the body of your message, and use the
title as a description of your question.
Do you have a specific question about the statement appearing in your title?
This one:
[at] {$var1{$var2}}
I can tell you that the syntax of that statement implies that %var1 is a
hash, $var2 is a scalar, the element of %var1 indexed by $var2 is
$var1{$var2} and is a reference to an array, and [at] {$var1{$var2}} is the
dereferenced array.
See 'perldoc perlref' for information about references in Perl.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: @{$var1{$var2}}
>>>>> "JG" == Jim Gibson <jimsgibson [at] gmail.com> writes:
JG> See 'perldoc perlref' for information about references in Perl.
even better for a newbie is to read 'perldoc perlreftut' and later
perllol and perldsc. leave perlref for when you have some experience
with refs under your belt and want more info.
uri
--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: @{$var1{$var2}}
Hi John,
On Wed, 22 Jun 2011 09:44:56 -0700 (PDT)
josanabr <john.sanabria [at] gmail.com> wrote:
> Hi,
>
> I'm reading a program written in perl and I read this statement
>
Well, assuming you are interested to learn about what [at] {$var1{$var2}} mean,
then:
1. $var1{$var2} is the value of the %var1 hash which is keyed by $var2.
2. [at] {$array_ref} dereferences the array $array_ref into an array.
Regards,
Shlomi Fish
--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman
Shlomi: if you read my stories, I=E2=80=99ll give you 1,000,000 virtual dol=
lars.
Sjors: causing me to have a lot of extra virtual time!
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: @{$var1{$var2}}
On 2011-06-22 18:44, josanabr wrote:
> I'm reading a program written in perl and I read this statement
[at] { $var1{ $var2 } }
Such variable names with numbers in them are often a sign of bad code.
What is the context?
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: @{$var1{$var2}}
On Jun 22, 12:49=A0pm, rco... [at] gmail.com (Rob Coops) wrote:
> On Wed, Jun 22, 2011 at 6:44 PM, josanabr <john.sanab... [at] gmail.com> wrote=
:
> ...
> Lets dissect this a little:
>
> Lets take the inner most thing ($var2) this is obviously a scalar (or a
> reference to another variable (I'll explain why I am betting it is a scal=
ar
> in a bit))
> Then we see the following: $var1{...} this is the way one accesses a
> variable in a hash based on the key (the thing that goes between those
> brackets). Usually the keys used in a has are scalars of course there is
> nothing stopping anyone from using complex data structures as a key but i=
t
> is performance wise not the smartest thing to do.
> The last bit then [at] {...} basically says treat what is in side the bracket=
s
> as an array (which is what one would do if one is expecting an array
> reference to be returned from $var1's value associated with key $var2.
>
> So what would the data structure look like?
> {
> =A0"Hash key 1" =3D> \[
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Array value 1',
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Array value 2',
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ],
> =A0"Hash key 2" =3D> \[
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Array value 1',
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Array value 2',
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0...
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ],
> =A0...
>
> }
Hm, I think it's worth noting though if you really want to
"treat what is in side the brackets as an array", you'd
likely be using a simpler data structure such as:
"Hash key 2" =3D [ "Array value 1", "Array value 2", ... ]
rather than:
"Hash key 2" =3D \[ "Array value 1", "Array value 2", ... ]
since the latter actually creates a ref to an anonymous
array. And, if it is a "ref to a ref", you'd need to deref
the original like this:
[at] { ${$var1{$var2}} }
rather than just: [at] { $var1{$var2} }
See: perldoc perlref
>
> Or in text form: $var1 is an hash containing keys associated with values
> which are references to arrays.
>
--
Charles DeRykus
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: @{$var1{$var2}}
I prefer to decode this kind of code from outside to inside.
1. The sigil [at] indicates the result is an array
2. Thus, $var1{$var2} should be an array reference
3. The structure of $var1{$var2} suggests var1 means a hash, or %var1
4. Thus, $var2 is a key of the hash %var1
So, %var1 is a hash of array reference, or the values of the hash %var1
are array references. [at] {$var1{$var2}} is trying to dereference the
references and get the arrays.
On 2011-6-23 0:44, josanabr wrote:
> Hi,
>
> I'm reading a program written in perl and I read this statement
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/