Quoting hash keys (was: To quote variables or not)

2012-05-23 Thread sono-io
On May 23, 2012, at 5:35 PM, John W. Krahn wrote: > Your question is not about quoting variables, which is bad, but about quoting > hash keys. On May 23, 2012, at 5:25 PM, Shawn H Corey wrote: > Yes, you can leave the quotes off if the key contains only alphanumerics. > Otherwise

Re: hash keys and readable code

2009-11-11 Thread Uri Guttman
> "PP" == Philip Potter writes: PP> 2009/11/11 Uri Guttman : >> you can also simplify the copy a little with a hash ref: >> >> my $readfsgs_flags = { map { $_ => $flags->{$_} } @flags_to_copy } ; PP> Is this really simpler than my version? PP> @readfsgs_fla...@flags_to_copy} =

Re: hash keys and readable code

2009-11-11 Thread Philip Potter
2009/11/11 Uri Guttman : >>>>>> "PP" == Philip Potter writes: > >  PP>     my %readfsgs_flags; >  PP>     my @flags_to_copy = qw(limit); # can scale up by adding more hash > keys here >  PP>     @readfsgs_fla...@flags_to_copy} = @{$flag.

Re: hash keys and readable code

2009-11-11 Thread Uri Guttman
>>>>> "PP" == Philip Potter writes: PP> my %readfsgs_flags; PP> my @flags_to_copy = qw(limit); # can scale up by adding more hash keys here PP> @readfsgs_fla...@flags_to_copy} = @{$flag...@flags_to_copy}; PP> my @results = readfsgs($

hash keys and readable code

2009-11-11 Thread Philip Potter
make it more scalable, I thought about doing it using hash slices: sub do_test { my ($testfilename, $flags) = @_; my %readfsgs_flags; my @flags_to_copy = qw(limit); # can scale up by adding more hash keys here @readfsgs_fla...@flags_to_copy} = @{$flag...@flags_to_cop

Re: Quoting hash keys changes things sometimes

2008-11-20 Thread Brian McCauley
On Nov 15, 6:52 pm, [EMAIL PROTECTED] (Kelly Jones) wrote: > Consider: > > perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' > [no result] > > perl -le '$hash{"foobar"} = 1; print $hash{foobar}' > 1 > > I sort of understand this: in the first script, Perl treats foo-bar as > a subtraction, and

Re: Quoting hash keys changes things sometimes

2008-11-19 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: >> Kelly Jones: >>> >>> Consider: >>> >>> perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' >>> [no result] >>> >>> perl -le '$hash{"foobar"} = 1; print $hash{foobar}' >>> 1 >>> >>> I sort of understand this: in the first script, Perl treats foo-bar >>> as a

Re: Quoting hash keys changes things sometimes

2008-11-16 Thread Dr.Ruud
Rob Dixon schreef: > Kelly Jones: >> Consider: >> >> perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' >> [no result] >> >> perl -le '$hash{"foobar"} = 1; print $hash{foobar}' >> 1 >> >> I sort of understand this: in the first script, Perl treats foo-bar >> as a subtraction, and sets $hash{

Re: [PBML] Quoting hash keys changes things sometimes

2008-11-15 Thread Chas. Owens
On Sat, Nov 15, 2008 at 17:42, Jenda Krynicky <[EMAIL PROTECTED]> wrote: snip > The rule for automatic quoting within $hash{...} is "if it looks like > word, it doesn't have to be quoted". And - is not in the list of word > characters as far as Perl is concerned. snip Not exactly. A hyphen is all

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread Rob Dixon
Kelly Jones wrote: > Consider: > > perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' > [no result] > > perl -le '$hash{"foobar"} = 1; print $hash{foobar}' > 1 > > I sort of understand this: in the first script, Perl treats foo-bar as > a subtraction, and sets $hash{0} to 1. In the second one

Re: [PBML] Quoting hash keys changes things sometimes

2008-11-15 Thread Jenda Krynicky
From: "Kelly Jones" <[EMAIL PROTECTED]> > Consider: > > perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' > [no result] > > perl -le '$hash{"foobar"} = 1; print $hash{foobar}' > 1 > > I sort of understand this: in the first script, Perl treats foo-bar as > a subtraction, and sets $hash{0} to

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread Chas. Owens
On Sat, Nov 15, 2008 at 15:10, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > s/pargmas/pragmas/; snip And I had paragams at one point. I need more (or better) sleep. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail:

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread John W. Krahn
Chas. Owens wrote: On Sat, Nov 15, 2008 at 13:52, Kelly Jones <[EMAIL PROTECTED]> wrote: Consider: perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' [no result] perl -le '$hash{"foobar"} = 1; print $hash{foobar}' 1 I sort of understand this: in the first script, Perl treats foo-bar as a s

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread John W. Krahn
Kelly Jones wrote: Consider: perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' [no result] Using warnings and/or strict may have helped: $ perl -Mwarnings -le 'my %hash = ("foo-bar", 1); print $hash{foo-bar}' Unquoted string "foo" may clash with future reserved word at -e line 1. Argument

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread Chas. Owens
On Sat, Nov 15, 2008 at 13:52, Kelly Jones <[EMAIL PROTECTED]> wrote: > Consider: > > perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' > [no result] > > perl -le '$hash{"foobar"} = 1; print $hash{foobar}' > 1 > > I sort of understand this: in the first script, Perl treats foo-bar as > a subtra

Quoting hash keys changes things sometimes

2008-11-15 Thread Kelly Jones
Consider: perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}' [no result] perl -le '$hash{"foobar"} = 1; print $hash{foobar}' 1 I sort of understand this: in the first script, Perl treats foo-bar as a subtraction, and sets $hash{0} to 1. In the second one it assumes you just left off some quot

Re: hash keys

2008-06-12 Thread John W. Krahn
Paul Lalli wrote: On Jun 12, 12:15 am, [EMAIL PROTECTED] (Beast) wrote: Why this following code has not working as expected? print "Number of element(s) : " . sprintf("%10d", keys(%hash) ) . "\n"; The keys() function does two different things, depending on context. In scalar context, it

Re: hash keys

2008-06-12 Thread Paul Lalli
On Jun 12, 12:15 am, [EMAIL PROTECTED] (Beast) wrote: > Why this following code has not working as expected? > >     print "Number of element(s) : " . sprintf("%10d", keys(%hash) ) . "\n"; The keys() function does two different things, depending on context. In scalar context, it returns the numb

Re: hash keys

2008-06-11 Thread Rob Dixon
beast wrote: > Hi All, > > > Why this following code has not working as expected? > > print "Number of element(s) : " . sprintf("%10d", keys(%hash) ) . "\n"; keys(%hash) returns the hash keys as a list, so sprintf("%10d", keys(

Re: hash keys

2008-06-11 Thread Rodrick Brown
On Thu, Jun 12, 2008 at 12:15 AM, beast <[EMAIL PROTECTED]> wrote: > Hi All, > > > Why this following code has not working as expected? > >print "Number of element(s) : " . sprintf("%10d", keys(%hash) ) . "\n"; > Try: print "Number of element(s): " . sprintf("%10d", scalar keys(%h)),"\n"; >

hash keys

2008-06-11 Thread beast
Hi All, Why this following code has not working as expected? print "Number of element(s) : " . sprintf("%10d", keys(%hash) ) . "\n"; Thanks. --budhi -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Deleting hash keys, but ending up with other keys

2007-02-19 Thread Rob Dixon
David Wagner wrote: > > I have two hashes and each is made up of two keys. One has only a numeric > value and the the second one has the detail. If I find out that I have right > situation, I change the numeric value in the first hash. I have done data > dumper where I create the hash and as I upd

Deleting hash keys, but ending up with other keys

2007-02-17 Thread Wagner, David --- Senior Programmer Analyst --- WGO
I have two hashes and each is made up of two keys. One has only a numeric value and the the second one has the detail. If I find out that I have right situation, I change the numeric value in the first hash. I have done data dumper where I create the hash and as I update the hash value and

Re: Re: unique hash keys

2006-10-23 Thread Romeo Theriault
On 10/23/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote: On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote: > Thank you Adriano, that works nicely after I added: > > use Memoize::AnyDBM_File; > > before that I was getting this error: > > AnyDBM_File doesn't define an EXISTS method at I

Re: unique hash keys

2006-10-23 Thread Adriano Ferreira
On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote: Thank you Adriano, that works nicely after I added: use Memoize::AnyDBM_File; before that I was getting this error: AnyDBM_File doesn't define an EXISTS method at I had not payed much attention to the fact that your code were using

Re: unique hash keys

2006-10-23 Thread Romeo Theriault
On Oct 23, 2006, at 8:45 AM, Adriano Ferreira wrote: On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote: This all works fine, but in the last step of the program I am trying to get the program to tell me key's that are unique to only the first hash. No matter what I do it always prints out

Re: unique hash keys

2006-10-23 Thread Adriano Ferreira
On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote: This all works fine, but in the last step of the program I am trying to get the program to tell me key's that are unique to only the first hash. No matter what I do it always prints out all of the values in the first hash, not the keys that

unique hash keys

2006-10-23 Thread Romeo Theriault
Hi, I'm playing with hashes trying to get myself more familiar with them. I have a little program below that has a hash with some keys and values in it. The program then copies some of the values/keys to another hash depending on their values. This all works fine, but in the last step of th

Re: question on Perl determinism with hash keys

2006-05-17 Thread Randal L. Schwartz
> "Gavin" == Gavin Bowlby <[EMAIL PROTECTED]> writes: Gavin> Does anyone have any performance data on this? Yes, tie kills hash access by about a factor of 10. Don't do it. Use *any* other means. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.sto

RE: question on Perl determinism with hash keys

2006-05-17 Thread Gavin Bowlby
ta on this? Regards, Gavin Bowlby -Original Message- From: Randal L. Schwartz [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 17, 2006 6:47 AM To: beginners@perl.org Subject: Re: question on Perl determinism with hash keys >>>>> ""Gavin" == "Gavin Bowl

Re: question on Perl determinism with hash keys

2006-05-17 Thread Randal L. Schwartz
> ""Gavin" == "Gavin Bowlby" <[EMAIL PROTECTED]> writes: "Gavin> It's important that user scripts are dispatched in identical order "Gavin> across runs for repeatability and debugging, and the general sanity of "Gavin> the users and the developer. Then add a serial number, and sort on that wh

RE: question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
2006 6:15 PM To: Gavin Bowlby; beginners@perl.org Subject: RE: question on Perl determinism with hash keys Understandable. Why do you need the keys function to return the keys in the same order? What is it that you're trying to do? -Original Message- From: Gavin Bowlby [mai

RE: question on Perl determinism with hash keys

2006-05-16 Thread Timothy Johnson
t: RE: question on Perl determinism with hash keys I don't want to do this sorting because I have many hashes within my Perl program that are changing at a high rate, and I'm trying to optimize performance within my Perl program. -Original Message- From: Timothy Johnson [mailto:[EMAIL P

RE: question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
5:47 PM To: Gavin Bowlby; beginners@perl.org Subject: RE: question on Perl determinism with hash keys I personally have never felt the need. One thing I'll often do is a foreach(sort keys %hash){ #do something... } If you know what the keys are going to be ahe

RE: question on Perl determinism with hash keys

2006-05-16 Thread Timothy Johnson
EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 5:37 PM To: Timothy Johnson; beginners@perl.org Subject: RE: question on Perl determinism with hash keys Timothy et al: Thanks, I did mean in the same order. Any idea on the relative performance of a hash tied to IxHash vs. a vanilla hash? I have a Perl pr

Re: question on Perl determinism with hash keys

2006-05-16 Thread John W. Krahn
Gavin Bowlby wrote: > All: Hello, > If I populate a %hash within a Perl program, is there any guarantee that > from run to run of the same Perl program the keys(%hash) function will > return identical sets of keys? Can I assume that you are worried about the order of the keys? Do you want the k

RE: question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
make this change... Gavin -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 5:28 PM To: Gavin Bowlby; beginners@perl.org Subject: RE: question on Perl determinism with hash keys If you mean in the same order, then no. perldoc -q

RE: question on Perl determinism with hash keys

2006-05-16 Thread Timothy Johnson
If you mean in the same order, then no. perldoc -q order -Original Message- From: Gavin Bowlby [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 16, 2006 5:25 PM To: beginners@perl.org Subject: question on Perl determinism with hash keys All: If I populate a %hash within a Perl program

question on Perl determinism with hash keys

2006-05-16 Thread Gavin Bowlby
All: If I populate a %hash within a Perl program, is there any guarantee that from run to run of the same Perl program the keys(%hash) function will return identical sets of keys? thanks for any insights on this, Gavin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail

Re: hash keys

2006-05-02 Thread Jay Savage
On 5/2/06, Rance Hall <[EMAIL PROTECTED]> wrote: the set of hash keys is what the computer uses to find values in the hash, and in order to optimize your code and make searching the hash for specific values as fast as possible, you should WANT your key to be as short and simple as possib

Re: hash keys

2006-05-02 Thread Rance Hall
Ryan Perry wrote: Generally, your hash value is larger than you key ( $hash{key}="Some text, maybe a sentence or two"). Is there any reason I should not reverse this relationship? ($hash{"Some text, maybe a sentence or two"}='key') Thanks! th

Re: hash keys

2006-05-01 Thread John W. Krahn
Ryan Perry wrote: > Generally, your hash value is larger than you key ( $hash{key}="Some > text, maybe a sentence or two"). Is there any reason I should not > reverse this relationship? ($hash{"Some text, maybe a sentence or > two"}='key

Re: hash keys

2006-05-01 Thread Tom Phoenix
t long keys should be avoided, except of course for whatever memory that they occupy. But anybody who worries about memory usage is probably using the wrong language. (Having said that, I should mention that perl does some clever memory-saving tricks on hash keys that it can't do on values. A

Re: hash keys

2006-05-01 Thread Jeff Pang
>Generally, your hash value is larger than you key ( $hash{key}="Some >text, maybe a sentence or two"). Is there any reason I should >not reverse this relationship? ($hash{"Some text, maybe a sentence or >two"}='key') There is not such rule for comparing Key and Value's size. For e

hash keys

2006-05-01 Thread Ryan Perry
Generally, your hash value is larger than you key ( $hash{key}="Some text, maybe a sentence or two"). Is there any reason I should not reverse this relationship? ($hash{"Some text, maybe a sentence or two"}='key') Thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additiona

Re: only one of two hash keys

2006-04-05 Thread Jay Savage
On 4/4/06, Lawrence Statton <[EMAIL PROTECTED]> wrote: > > Is there a nice clean perl way to test to see if only one key of a hash > > has data? > > > > %some_hash = ( key1 => 1, key2 => 2 ); should fail the test > > %some_hash = ( key2 => 2 ); should pass the test > > %some_hash = ( key1 => 1 ); s

Re: only one of two hash keys

2006-04-05 Thread John Ackley
perl wrote: Is there a nice clean perl way to test to see if only one key of a hash has data? %some_hash = ( key1 => 1, key2 => 2 ); should fail the test %some_hash = ( key2 => 2 ); should pass the test %some_hash = ( key1 => 1 ); should pass the test Thank you print keys(%some_hash) == 1

Re: only one of two hash keys

2006-04-04 Thread Lawrence Statton
> Is there a nice clean perl way to test to see if only one key of a hash > has data? > > %some_hash = ( key1 => 1, key2 => 2 ); should fail the test > %some_hash = ( key2 => 2 ); should pass the test > %some_hash = ( key1 => 1 ); should pass the test > %some_hash = ( key1 => 1, key2 => 2, key3 =>

Re: only one of two hash keys

2006-04-04 Thread perl
On Wed, 2006-04-05 at 09:35 +0800, Jeff Pang wrote: > Hello, > > [EMAIL PROTECTED] ~/app]$ perl -le '%some_hash=(aa=>'bb');scalar keys > %some_hash == 1 ? print "true" : print "false"' > true > [EMAIL PROTECTED] ~/app]$ perl -le '%some_hash=(aa=>'bb',cc=>'dd');scalar > keys %some_hash == 1 ? pri

Re: only one of two hash keys

2006-04-04 Thread Jeff Pang
some_hash == 1 ? print "true" : print "false"' false Is it useful for you? -Original Message- >From: perl <[EMAIL PROTECTED]> >Sent: Apr 5, 2006 9:26 AM >To: beginners@perl.org >Subject: only one of two hash keys > >Is there a nice clean perl way to

only one of two hash keys

2006-04-04 Thread perl
Is there a nice clean perl way to test to see if only one key of a hash has data? %some_hash = ( key1 => 1, key2 => 2 ); should fail the test %some_hash = ( key2 => 2 ); should pass the test %some_hash = ( key1 => 1 ); should pass the test Thank you -- To unsubscribe, e-mail: [EMAIL PROTECTED]

RE: HASH keys in exact order

2005-12-22 Thread Timothy Johnson
, Dzenan [mailto:[EMAIL PROTECTED] Sent: Thursday, December 22, 2005 2:19 PM To: beginners@perl.org Subject: HASH keys in exact order I am trying to print HASH keys in exact order as they are defined, but "keys %HASH" returns them in a random order, "sort" is not going to work eit

Re: HASH keys in exact order

2005-12-22 Thread Paul Johnson
On Thu, Dec 22, 2005 at 05:18:35PM -0500, Causevic, Dzenan wrote: > I am trying to print HASH keys in exact order as they are defined, but > "keys %HASH" returns them in a random order, "sort" is not going to > work either because keys are strings that are not define

HASH keys in exact order

2005-12-22 Thread Causevic, Dzenan
I am trying to print HASH keys in exact order as they are defined, but "keys %HASH" returns them in a random order, "sort" is not going to work either because keys are strings that are not defined in the exact alphabetical order. Is there a way to get %HASH keys in the or

Re: Comparing an array with hash keys

2005-09-30 Thread Peter Rabbitson
> ... or grep > > my @storage_array = grep { exists $original_hash{$_} } @original_array; > Disregard that, didn't read the question/answer well enough. Bummer... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Comparing an array with hash keys

2005-09-30 Thread Peter Rabbitson
On Fri, Sep 30, 2005 at 10:08:51AM -0400, Jeff 'japhy' Pinyan wrote: > On Sep 30, Mark Martin said: > > >I want to compare the elements of an array with the keys in a hash. If > >matches are found, I want to store the values associated with the > >matched keys in an array for future processing :

Re: Comparing an array with hash keys

2005-09-30 Thread Jeff 'japhy' Pinyan
On Sep 30, Mark Martin said: I want to compare the elements of an array with the keys in a hash. If matches are found, I want to store the values associated with the matched keys in an array for future processing : my @storage_array = (); foreach $item(@original array) { if (exists $

Comparing an array with hash keys

2005-09-30 Thread Mark Martin
Hi, I want to compare the elements of an array with the keys in a hash. If matches are found, I want to store the values associated with the matched keys in an array for future processing : my @storage_array = (); foreach $item(@original array) {

Re: Assigning a variable to hash keys and values

2004-06-29 Thread John W. Krahn
Daniel Falkenberg wrote: > > Hello All, Hello, > I currently have a hash of a hash... > > > %HoH = ( > > Key1=> { > > Apple => "Green", > > Banna => "Yellow", > > }, > > Key2=> { > > Carrot=> "Or

Re: Assigning a variable to hash keys and values

2004-06-29 Thread Philipp Traeder
On Tuesday 29 June 2004 08:49, Daniel Falkenberg wrote: > Hello All, Hi Dan, > I currently have a hash of a hash... > > > %HoH = ( > > Key1=> { > > Apple => "Green", > > Banna => "Yellow", > > }, > > Key2=> { > >

Re: Assigning a variable to hash keys and values

2004-06-29 Thread Ramprasad A Padmanabhan
On Tue, 2004-06-29 at 12:19, Daniel Falkenberg wrote: > Hello All, > > I currently have a hash of a hash... > > > %HoH = ( > > Key1=> { > > Apple => "Green", > > Banna => "Yellow", > > }, > > Key2=> { > >

Assigning a variable to hash keys and values

2004-06-29 Thread Daniel Falkenberg
Hello All, I currently have a hash of a hash... > %HoH = ( > Key1=> { > Apple => "Green", > Banna => "Yellow", > }, > Key2=> { > Carrot=> "Orange", > Tomoatoe => "Red", > }

RE: Adding Arrays as Hash Keys

2004-06-20 Thread Tim Johnson
use the syntax above to access the values or dereference the array, like so: @{$hash{firstarray}} if you wanted to use sort(), shift(), etc. -Original Message- From: gohaku [mailto:[EMAIL PROTECTED] Sent: Sat 6/19/2004 10:04 PM To: Perl Beginners Cc:

Re: Adding Arrays as Hash Keys

2004-06-20 Thread John W. Krahn
Gohaku wrote: > > Hello everyone, Hello, > I would like to know if there is a cleaner way of Merging Hash Keys > with Arrays > and what the correct terminology is for describing this merging. > I find the syntax somewhat confusing since @ usually refers to an Array or a slice

RE: Adding Arrays as Hash Keys

2004-06-19 Thread Charles K. Clarkson
From: gohaku <mailto:[EMAIL PROTECTED]> wrote: : I would like to know if there is a cleaner way of Merging : Hash Keys with Arrays and what the correct terminology is : for describing this merging. : I find the syntax somewhat confusing since @ usually refers : to an Array while : % refer

Adding Arrays as Hash Keys

2004-06-19 Thread gohaku
Hello everyone, I would like to know if there is a cleaner way of Merging Hash Keys with Arrays and what the correct terminology is for describing this merging. I find the syntax somewhat confusing since @ usually refers to an Array while % refers to a Hash @array = qw(1 2 3 4 5); #Hash Key and

Re: How to map hash keys only, not values?

2003-03-14 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote: > Hi Joseph, > > >Probably just as well. Is there some context where you anticipate having > to repair broken keys after the fact? > > In this case I'm building packages, and don't want to count on the user to > get the case of the text correct when passing the values. L

Re: How to map hash keys only, not values?

2003-03-14 Thread Peter_Farrar
Hi Joseph, >Probably just as well. Is there some context where you anticipate having to repair broken keys after the fact? In this case I'm building packages, and don't want to count on the user to get the case of the text correct when passing the values. So if I need to set the 'smile' attrib

Re: How to map hash keys only, not values?

2003-03-13 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote: > >Replace > > > > EVIL: map { some;block;of;code;that;changes;$_ } @some_array; > > > >with > > > > GOOD: for (@some_array) { some;block;of;code;that;changes;$_ } > > I guess I don't get it. Map returns a value and I ignore it; so what? > What side effects does this ha

Re: How to map hash keys only, not values?

2003-03-13 Thread david
Randal L. Schwartz wrote: >> "Peter" == Peter Farrar <[EMAIL PROTECTED]> writes: > >>> Replace >>> >>> EVIL: map { some;block;of;code;that;changes;$_ } @some_array; >>> >>> with >>> >>> GOOD: for (@some_array) { some;block;of;code;that;changes;$_ } > > > The foreach loop *will* be faster

Re: How to map hash keys only, not values?

2003-03-13 Thread John W. Krahn
Peter Farrar wrote: > > Hi All, Hello, > I'm passing a hash to a subroutine like this: > subname("a" => 123, "b" =>"fff", "C" => "joyjoyjoy"); > > On the receiving side I want all keys to be upper case. I can map like > this: > sub subname{ > map {$_ =~ tr/a-z/A-Z/} @_;

Re: How to map hash keys only, not values?

2003-03-13 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote: > Hi All, > > I'm passing a hash to a subroutine like this: > subname("a" => 123, "b" =>"fff", "C" => "joyjoyjoy"); Hi Peter, You probably sholdn't be doing this. Keys, whether in a hash or a database table, are primary references. They should not be modified af

Re: How to map hash keys only, not values?

2003-03-13 Thread Peter_Farrar
>The foreach loop *will* be faster. Good enough for me! Thanks, Peter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: How to map hash keys only, not values?

2003-03-13 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote: > >First, please don't use map in a void context for its side effects. > > Uh oh... What side effects? I use map like this all the time! What dread > is looming in my future? Do: perldoc -f map and read carefully the second paragraph of discussion: Note that

Re: How to map hash keys only, not values?

2003-03-13 Thread Randal L. Schwartz
> "Peter" == Peter Farrar <[EMAIL PROTECTED]> writes: >> Replace >> >> EVIL: map { some;block;of;code;that;changes;$_ } @some_array; >> >> with >> >> GOOD: for (@some_array) { some;block;of;code;that;changes;$_ } Peter> I guess I don't get it. Map returns a value and I ignore it; so what?

Re: How to map hash keys only, not values?

2003-03-13 Thread Peter_Farrar
>Replace > > EVIL: map { some;block;of;code;that;changes;$_ } @some_array; > >with > > GOOD: for (@some_array) { some;block;of;code;that;changes;$_ } I guess I don't get it. Map returns a value and I ignore it; so what? What side effects does this have? Which one's faster? I like to avoid ob

RE: How to map hash keys only, not values?

2003-03-13 Thread NYIMI Jose (BMB)
unc manpage. José. > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 13, 2003 5:43 PM > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Subject: Re: How to map hash keys only, not values? > > > > > &g

Re: How to map hash keys only, not values?

2003-03-13 Thread Randal L. Schwartz
> "Peter" == Peter Farrar <[EMAIL PROTECTED]> writes: >> First, please don't use map in a void context for its side effects. Peter> Uh oh... What side effects? I use map like this all the time! What dread Peter> is looming in my future? Replace EVIL: map { some;block;of;code;that;change

Re: How to map hash keys only, not values?

2003-03-13 Thread Peter_Farrar
>First, please don't use map in a void context for its side effects. Uh oh... What side effects? I use map like this all the time! What dread is looming in my future? >Just loop it: > >sub subname { > my %values; > while (@_ >= 2) { >my ($key, $value) = splice @_, 0, 2;

Re: How to map hash keys only, not values?

2003-03-13 Thread Randal L. Schwartz
> "Peter" == Peter Farrar <[EMAIL PROTECTED]> writes: Peter> Hi All, Peter> I'm passing a hash to a subroutine like this: Peter> subname("a" => 123, "b" =>"fff", "C" => "joyjoyjoy"); Peter> On the receiving side I want all keys to be upper case. I can map like Peter> this: Peter>

How to map hash keys only, not values?

2003-03-13 Thread Peter_Farrar
Hi All, I'm passing a hash to a subroutine like this: subname("a" => 123, "b" =>"fff", "C" => "joyjoyjoy"); On the receiving side I want all keys to be upper case. I can map like this: sub subname{ map {$_ =~ tr/a-z/A-Z/} @_; my %values = @_; ..

Re: help with nearly identical hash keys

2003-02-25 Thread Katy Brownfield
Here's a simpler example that contains some tools that might be useful to you. (Sorry for the lazy hash declarations.) If you explain the bigger picture, you might get suggestions for data structures that can be manipulated more simply. Katy my %one = qw(_cat peach _dog apple _mouse apricot

Re: help with nearly identical hash keys

2003-02-25 Thread Lance
something like: foreach my $key( keys %hashA ){ if( $hashB{$key}){ print"do the dance of joy, duplicate key found" } } should do the trick. "Aimal Pashtoonmal" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello people, > > Can any one please help me. I have 2 hashes, hashA a

RE: help with nearly identical hash keys

2003-02-25 Thread Aimal Pashtoonmal
Hello people, Can any one please help me. I have 2 hashes, hashA and hashB, the keys in both cases, are made up of a mixture of numbers and words etc. But the keys are differnt so I presume I cannot use if exits or if defined. Is there anyway of check to see if the words and numbers making up the

Re: converting hash keys to uppercase with regex

2002-06-18 Thread zentara
On Mon, 17 Jun 2002 16:55:08 -0700, [EMAIL PROTECTED] (Drieux) wrote: > >given that your code would generate >$vc{'TZ'} = 'ok';$vc{'UA'} = 'ok';$vc{'UG'} = 'ok';$vc{'UK'} = >'ok';$vc{'UM'} = 'ok'; >$vc{'US'} = 'ok';$vc{'UY'} = 'ok';$vc{'UZ'} = 'ok';$vc{'VA'} = >'ok';$vc{'VC'} = 'ok'; >$vc{'VE'}

Re: Extracting values from hash keys

2002-04-11 Thread John W. Krahn
Dave Chappell wrote: > > Hi, Hello, > I have a hash that will have some keys contain single values and other keys > that will have multiple values: > > %hash = ( > key1 => 'test-1', > key2 => ['test-2-0', 'test-2-1'], > key3 => 'test-3' > ); The simple answer is to put all values

RE: Extracting values from hash keys

2002-04-11 Thread Nikola Janceski
print ")\n"; } else { print "$key = $hash{$key}\n"; } } > -Original Message- > From: Dave Chappell [mailto:[EMAIL PROTECTED]] > Sent: Thursday, April 11, 2002 11:02 AM > To: [EMAIL PROTECTED] > Subject: Extracting

Extracting values from hash keys

2002-04-11 Thread Dave Chappell
Hi, I have a hash that will have some keys contain single values and other keys that will have multiple values: %hash = ( key1 => 'test-1', key2 => ['test-2-0', 'test-2-1'], key3 => 'test-3' ); I want to loop t

Re: Large hash keys & hash performance

2002-03-26 Thread Jenda Krynicky
From: Mr Hash <[EMAIL PROTECTED]> > On 03/26, Jenda Krynicky said something like: > > From: "Jonathan E. Paton" <[EMAIL PROTECTED]> > > > > affect the performance of: > > > > key listings (things like grep /pattern/, keys %hash) > > > > > > Grep can be slow, especially with patterns

Re: Large hash keys & hash performance

2002-03-26 Thread Mr Hash
On 03/26, Jenda Krynicky said something like: > From: "Jonathan E. Paton" <[EMAIL PROTECTED]> > > > affect the performance of: > > > key listings (things like grep /pattern/, keys %hash) > > > > Grep can be slow, especially with patterns. Keys > > could be slow, especially if the d

Re: Large hash keys & hash performance

2002-03-26 Thread Jenda Krynicky
From: "Jonathan E. Paton" <[EMAIL PROTECTED]> > > affect the performance of: > > key listings (things like grep /pattern/, keys %hash) > > Grep can be slow, especially with patterns. Keys > could be slow, especially if the dataset is large. Maybe you could try to use whil

Re: Large hash keys & hash performance

2002-03-26 Thread Jonathan E. Paton
> How do the following attribute of a hash key: > size (something like an alphanumeric > string about 70 chars wide) Longer strings take longer to hash, but 70 characters isn't massive. Hashing a string takes time proportional to the length of the string. > similarity (groups of abo

Large hash keys & hash performance (sorry if duplicated)

2002-03-26 Thread Mr Hash
like grep /pattern/, keys %hash) key lookups (referencing $hash{$key}) What are the key factors in /good performing/ hash keys? Thank you for your input. -- Shawn Leas [EMAIL PROTECTED] I bought a dog the other day... I named him Stay. It's fun to call him... "Come here, Stay!

Large hash keys & hash performance

2002-03-26 Thread Shawn
like grep /pattern/, keys %hash) key lookups (referencing $hash{$key}) What are the key factors in /good performing/ hash keys? Thank you for your input. -- Shawn Leas [EMAIL PROTECTED] I used to work in a fire hydrant factory. You couldn't park anywhere near the

RE: sort order of hash keys

2002-02-26 Thread Wagner-David
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 26, 2002 03:37 To: [EMAIL PROTECTED] Subject: Re: sort order of hash keys yeah, i new this was tricky. my hash keys / values have uneven names so i cant use a sort routine directly. thats why i would like to get the key / valu

RE: sort order of hash keys

2002-02-26 Thread Jeff 'japhy' Pinyan
On Feb 26, Richard Smith said: >Try the fields module. This sounds like an ideal place to use a pseudo-hash EWWW. Pseudo-hashes were a blight on Perl. They slowed things down all over the place. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia broth

RE: sort order of hash keys

2002-02-26 Thread Richard Smith
Try the fields module. This sounds like an ideal place to use a pseudo-hash Thanx, Smiddy .. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: sort order of hash keys

2002-02-26 Thread Jeff 'japhy' Pinyan
On Feb 26, Martin A. Hansen said: >i would like to know if theres a smart way to unwind a hashtable so that >the key / value pairs comes out in the same order as they are in the table. What "table"? If you'd like a hash to stay in the order you CREATED it in, use the Tie::IxHash module. -- Je

RE: sort order of hash keys

2002-02-26 Thread John Edwards
This maybe... Tie::LLHash.pm -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: 26 February 2002 11:37 To: [EMAIL PROTECTED] Subject: Re: sort order of hash keys yeah, i new this was tricky. my hash keys / values have uneven names so i cant use a sort routine

Re: sort order of hash keys

2002-02-26 Thread Martin A. Hansen
yeah, i new this was tricky. my hash keys / values have uneven names so i cant use a sort routine directly. thats why i would like to get the key / values in the same order as they are in the hashtable file. whats the name of that hash modules? :o) martin On Tue, Feb 26, 2002 at 10:28

  1   2   >