Re: Hash Key function puzzlement -- a point of information query

2012-05-03 Thread Leo Susanto
keys is a function, it doesn't take in value

On Thu, May 3, 2012 at 9:08 AM, Rothenmaier, Deane
deane.rothenma...@walgreens.com wrote:
 Gurus,



 Given something like this:



 #!Perl

 use strict;

 use warnings;



 my %hash; keys(%hash) = 128;



 print “hash has “ . scalar(keys(%hash)) . “ keys\n”;



 I should see a printed value of 128, wouldn’t you think? But no, it prints:
 “hash has 0 keys”.  What’s up wit dat? What obvious thing am I missing?



 Thanks,



 Deane Rothenmaier

 Programmer/Analyst – IT-StdCfg

 Walgreens Corp.

 2 Overlook Point #N51022D

 MS 6515

 Lincolnshire, IL 60069

 224-542-5150



 The more corrupt the republic, the more numerous the laws. -- Tacitus




 ___
 Perl-Win32-Users mailing list
 Perl-Win32-Users@listserv.ActiveState.com
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Hash Key function puzzlement -- a point of information query

2012-05-03 Thread Aaron Hawryluk
What Leo said. keys(%hash) returns the keys from the hash as an array,
you can't assign to it AFAIK.

On Thu, May 3, 2012 at 10:18 AM, Leo Susanto leosusa...@gmail.com wrote:
 keys is a function, it doesn't take in value

 On Thu, May 3, 2012 at 9:08 AM, Rothenmaier, Deane
 deane.rothenma...@walgreens.com wrote:
 Gurus,



 Given something like this:



 #!Perl

 use strict;

 use warnings;



 my %hash; keys(%hash) = 128;



 print “hash has “ . scalar(keys(%hash)) . “ keys\n”;



 I should see a printed value of 128, wouldn’t you think? But no, it prints:
 “hash has 0 keys”.  What’s up wit dat? What obvious thing am I missing?



 Thanks,



 Deane Rothenmaier

 Programmer/Analyst – IT-StdCfg

 Walgreens Corp.

 2 Overlook Point #N51022D

 MS 6515

 Lincolnshire, IL 60069

 224-542-5150



 The more corrupt the republic, the more numerous the laws. -- Tacitus




 ___
 Perl-Win32-Users mailing list
 Perl-Win32-Users@listserv.ActiveState.com
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

 ___
 Perl-Win32-Users mailing list
 Perl-Win32-Users@listserv.ActiveState.com
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Hash Key function puzzlement -- a point of information query

2012-05-03 Thread Tobias Hoellrich
Keys can be used as an lvalue. 

$ perldoc -f keys
...
As an lvalue keys allows you to increase the number of hash
buckets allocated for the given hash. This can gain you a
measure of efficiency if you know the hash is going to get big.
(This is similar to pre-extending an array by assigning a larger
number to $#array.) If you say

keys %hash = 200;
...

That said, using it as an lvalue does not magically create random keys in the 
hash. It just gives the interpreter a hint on how much memory should be 
allocated for it. 

--Tobias



 -Original Message-
 From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-
 win32-users-boun...@listserv.activestate.com] On Behalf Of Aaron
 Hawryluk
 Sent: Thursday, May 03, 2012 10:23 AM
 To: Rothenmaier, Deane; perl-win32-users@listserv.ActiveState.com
 Subject: Re: Hash Key function puzzlement -- a point of information query
 
 What Leo said. keys(%hash) returns the keys from the hash as an array, you
 can't assign to it AFAIK.
 
 On Thu, May 3, 2012 at 10:18 AM, Leo Susanto leosusa...@gmail.com
 wrote:
  keys is a function, it doesn't take in value
 
  On Thu, May 3, 2012 at 9:08 AM, Rothenmaier, Deane
  deane.rothenma...@walgreens.com wrote:
  Gurus,
 
 
 
  Given something like this:
 
 
 
  #!Perl
 
  use strict;
 
  use warnings;
 
 
 
  my %hash; keys(%hash) = 128;
 
 
 
  print “hash has “ . scalar(keys(%hash)) . “ keys\n”;
 
 
 
  I should see a printed value of 128, wouldn’t you think? But no, it prints:
  “hash has 0 keys”.  What’s up wit dat? What obvious thing am I missing?
 
 
 
  Thanks,
 
 
 
  Deane Rothenmaier
 
  Programmer/Analyst – IT-StdCfg
 
  Walgreens Corp.
 
  2 Overlook Point #N51022D
 
  MS 6515
 
  Lincolnshire, IL 60069
 
  224-542-5150
 
 
 
  The more corrupt the republic, the more numerous the laws. -- Tacitus
 
 
 
 
  ___
  Perl-Win32-Users mailing list
  Perl-Win32-Users@listserv.ActiveState.com
  To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
 
  ___
  Perl-Win32-Users mailing list
  Perl-Win32-Users@listserv.ActiveState.com
  To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
 ___
 Perl-Win32-Users mailing list
 Perl-Win32-Users@listserv.ActiveState.com
 To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Hash Key function puzzlement -- a point of information query

2012-05-03 Thread Brian Raven

From: perl-win32-users-boun...@listserv.activestate.com 
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of 
Rothenmaier, Deane
Sent: 03 May 2012 17:08
To: perl-win32-users@listserv.ActiveState.com
Subject: Hash Key function puzzlement -- a point of information query

 Gurus,

 Given something like this:

 #!Perl
 use strict;
 use warnings;

 my %hash; keys(%hash) = 128;

You have changed the number of hash buckets, not the number of keys.


 print hash has  . scalar(keys(%hash)) .  keys\n;

 I should see a printed value of 128, wouldn't you think? But no, it prints: 
 hash has 0 keys.  What's up wit  dat? What obvious thing am I missing?

That's correct, because you have not added any keys.

HTH


--
Brian Raven




Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs