[newbie] how to get just the first value of a hash??

  • Thread starter Janek Schleicher
  • Start date
A

Anno Siegel

Keith Keller said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



In scalar context, will keys run through the whole hash? If so,
then it doesn't sound the same as Anno's suggested ''uneach''.

No, it won't. It does hash magic and retrieves the number of keys
directly. It also resets each-iteration.

Anno
 
U

Uri Guttman

KK> In scalar context, will keys run through the whole hash? If so,
KK> then it doesn't sound the same as Anno's suggested ''uneach''.

from doop.c:

if (! SvTIED_mg((SV*)keys, 'P'))
i = HvKEYS(keys);
else {
i = 0;
/*SUPPRESS 560*/
while (hv_iternext(keys)) i++;
}

and HvKEYS is a macro that gets the key count from the hv. so it looks
like it is O(1)

uri
 
J

Jürgen Exner

Guest1 wrote:
[see subject]

Hashes are mappings and by definition don't have an order, therefore there
is no first element or first value.
Or how would you select the first value of let's say the cubicroot function?

jue
 
J

Jürgen Exner

Brian said:
Well, we're all entitled to oppinions. I don't think it's difficult to
jump to the end of the message and delete a few lines when replying.
And the only reason it got so ugly in our quoting is because we
quoted the sigs, because thats what we were discussing.

If it would be a sig then probably nobody would complain because smart
Newsreaders will remove the sig automatically in replies.
Unfortunately it is not marked a sig, so it is body content, and will be
copied automatically, and requires manual effort to be removed.

Sucks IMHO

jue
 
T

Tassilo v. Parseval

Also sprach Jürgen Exner:
Guest1 wrote:
[see subject]

Hashes are mappings and by definition don't have an order, therefore there
is no first element or first value.
Or how would you select the first value of let's say the cubicroot function?

Well, the first one is probably 0 (at least for real numbers). The
challenge is to find the second value since it has a non-discrete
carrier.

Tassilo
 
D

Dave Saville

Guest1 wrote at Wed, 03 Sep 2003 14:52:22 +0100:

You can't.
Hashs are unsorted, so there is no first key or value.

What I thought the OP meant was something I had wondered myself. If you
have a function/module/whatever that returns a hash and you happen to
*know* that there will only be one value in it, is there an easy way to
get that single value?

Regards

Dave Saville

NB switch saville for nospam in address
 
A

Anno Siegel

Dave Saville said:
What I thought the OP meant was something I had wondered myself. If you
have a function/module/whatever that returns a hash and you happen to
*know* that there will only be one value in it, is there an easy way to
get that single value?

Sure:

my ( $value) = values %hash;

Anno
 
J

Jürgen Exner

Tassilo said:
Also sprach Jürgen Exner:
Guest1 wrote:
[see subject]

Hashes are mappings and by definition don't have an order, therefore
there is no first element or first value.
Or how would you select the first value of let's say the cubicroot
function?

Well, the first one is probably 0 (at least for real numbers). The
challenge is to find the second value since it has a non-discrete
carrier.

You fell for the trap ;-)
For squareroot(x) you are probably right.
But I was talking about cubicroot and I would think that -5 comes before 0.

You could also argue that in case of squareroot i comes before 0. But there
are too many people who don't know complex numbers, therefore it makes a
poor example.

jue
 
T

Tassilo v. Parseval

Also sprach Jürgen Exner:
Tassilo said:
Also sprach Jürgen Exner:
Guest1 wrote:
[see subject]

Hashes are mappings and by definition don't have an order, therefore
there is no first element or first value.
Or how would you select the first value of let's say the cubicroot
function?

Well, the first one is probably 0 (at least for real numbers). The
challenge is to find the second value since it has a non-discrete
carrier.

You fell for the trap ;-)
For squareroot(x) you are probably right.
But I was talking about cubicroot and I would think that -5 comes before 0.

Oups, right. :) I somehow failed to see that the cubicroot is x^(1/3) and
not x^(1/2).
You could also argue that in case of squareroot i comes before 0. But there
are too many people who don't know complex numbers, therefore it makes a
poor example.

Well, i would be part of the result anyway (when taking the squareroot
of a negative number). If you define the range of your result to be
within the real numbers, the smallest input that is allowed is 0.

But indeed, finding the first number is even harder for complex numbers
since you suddenly have two dimensions to consider.

Tassilo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top