Re: swap keys and values

2012-03-21 Thread lina
On Wed, Mar 21, 2012 at 9:04 PM, Mendor wrote: > You can use reverse() for this, can't you? Thanks for both of you. I didn't know the reverse() can do this, and didn't realize how mature the perl has evolved. About the $array, before I mistook %h as %array, later writing email I realize this.

Re: swap keys and values

2012-03-21 Thread Shlomi Fish
ׁHi Lina, On Wed, 21 Mar 2012 21:00:53 +0800 lina wrote: > Hi, > > I tried to write something, but chocked in the end, > > Thanks ahead for your advice, > > #!/usr/bin/env perl > > use strict; > use warnings; > > my %h = ( > 1 => "a", > 2 => "b", > 3 => "c" > ); > > forea

Re: swap keys and values

2012-03-21 Thread Mendor
You can use reverse() for this, can't you? -- Regards. On 21.03.2012 17:00, lina wrote: Hi, I tried to write something, but chocked in the end, Thanks ahead for your advice, #!/usr/bin/env perl use strict; use warnings; my %h = ( 1 => "a", 2 => "b", 3 => "c" );

swap keys and values

2012-03-21 Thread lina
Hi, I tried to write something, but chocked in the end, Thanks ahead for your advice, #!/usr/bin/env perl use strict; use warnings; my %h = ( 1 => "a", 2 => "b", 3 => "c" ); foreach my $key ( sort keys %h){ $h{$h{$key}}=$key; delete $h{$key}; }

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: Keys and values

2002-02-09 Thread Jeff 'japhy' Pinyan
On Feb 9, Matt C. said: >my @array=split; #split on space by default >$HASH{ $array[0] } = @array[1,2]; > ># Above is the slice. Notice the @arry[1,2]; it's in array context. No, it's in scalar context. $x = @array[1,2]; is like $x = ($array[1], $array[2]); which sets $x to

Re: Keys and values

2002-02-09 Thread Matt C.
This example shows an array slice, which can be very useful from time to time (although the example Briac wrote saves a step). This would make a good one liner. #!/usr/local/bin/perl -w use strict; my %HASH; while(){ my @array=split; #split on space by default $HASH{ $array[0] } = @array

Re: Keys and values

2002-02-09 Thread Briac Pilpré
On Sat, 09 Feb 2002 13:49:59 +, Terri Harrison <[EMAIL PROTECTED]> wrote: > What do I do so that the Name is the key and the Species and Gender > together are the value? You were not too far from what you wanted to do. #!/usr/bin/perl -w use strict; my %zoo; while (){ chomp;

Keys and values

2002-02-09 Thread terri harrison
If this is my input: Happy Cat Male Evil Snake Female Patches Dog Male Bubbles Fish Female Harley dog Female Goldy Fish Male What do I do so that the Name is the key and the Species and Gender together are the value? while (<>) { chomp; %chars = split(' ', $_); $chars{