Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

WWWXXXAPC, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text, how to setup procmail html2text, WWWXXXAPC., XXXCNZZZ

Links

XODOX
Impressum

#1: @{$var1{$var2}}

Posted on 2011-06-22 18:44:56 by josanabr

Hi,

I'm reading a program written in perl and I read this statement


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

Report this message

#2: Re: @{$var1{$var2}}

Posted on 2011-06-22 21:49:24 by Rob Coops

--0015175cf75822e6f604a652455e
Content-Type: text/plain; charset=UTF-8

On Wed, Jun 22, 2011 at 6:44 PM, josanabr <john.sanabria@gmail.com> wrote:

> Hi,
>
> I'm reading a program written in perl and I read this statement
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@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 @{...} 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--

Report this message

#3: Re: @{$var1{$var2}}

Posted on 2011-06-22 21:58:13 by Jim Gibson

On 6/22/11 Wed Jun 22, 2011 9:44 AM, "josanabr" <john.sanabria@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:

@{$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 @{$var1{$var2}} is the
dereferenced array.

See 'perldoc perlref' for information about references in Perl.



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

Report this message

#4: Re: @{$var1{$var2}}

Posted on 2011-06-22 22:16:41 by Uri Guttman

>>>>> "JG" == Jim Gibson <jimsgibson@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@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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#5: Re: @{$var1{$var2}}

Posted on 2011-06-22 22:22:48 by Shlomi Fish

Hi John,

On Wed, 22 Jun 2011 09:44:56 -0700 (PDT)
josanabr <john.sanabria@gmail.com> wrote:

> Hi,
>=20
> I'm reading a program written in perl and I read this statement
>=20

Well, assuming you are interested to learn about what @{$var1{$var2}} mean,
then:

1. $var1{$var2} is the value of the %var1 hash which is keyed by $var2.

2. @{$array_ref} dereferences the array $array_ref into an array.

Regards,

Shlomi Fish

--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Shlomi: if you read my stories, Iâ€=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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#6: Re: @{$var1{$var2}}

Posted on 2011-06-23 08:40:43 by rvtol+usenet

On 2011-06-22 18:44, josanabr wrote:

> I'm reading a program written in perl and I read this statement

@{ $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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#7: Re: @{$var1{$var2}}

Posted on 2011-06-23 12:41:44 by derykus

On Jun 22, 12:49=A0pm, rco...@gmail.com (Rob Coops) wrote:
> On Wed, Jun 22, 2011 at 6:44 PM, josanabr <john.sanab...@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 @{...} 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:

@{ ${$var1{$var2}} }

rather than just: @{ $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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#8: Re: @{$var1{$var2}}

Posted on 2011-07-06 12:26:40 by Dejian Zhao

I prefer to decode this kind of code from outside to inside.

1. The sigil @ 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. @{$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@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message