Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Multi-dim hash slices

Reply
Thread Tools

Multi-dim hash slices

 
 
Dinko Korunic
Guest
Posts: n/a
 
      01-17-2005
Hi. Is it possible to use hash slices with multi-dimensional hashes (and
how)? If yes, would hash slices be in any way faster for code that
basically does:

$hash{$array_elem1}{$array_elem2} = 1;

for each element of each array?

TIA.

--
| |--.----.-----. Dinko 'kreator' Korunic #include <stddisclaimer.h>
| <| _| -__| http://kreator.esa.fer.hr/ | http://kre.deviantart.com/
|__|__|__| |_____| PGP:0xEA160D0B | IRC:kre | ICQ:16965294 | AIM:kreatorMoo
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-17-2005
Dinko Korunic wrote:
> Is it possible to use hash slices with multi-dimensional hashes (and
> how)?


Yes. Example:

my %hash;
my @keys = qw/foo bar baz/;
@{ $hash{abc} }{ @keys } = (1) x @keys;

> If yes, would hash slices be in any way faster for code that
> basically does:
>
> $hash{$array_elem1}{$array_elem2} = 1;
>
> for each element of each array?


If speed is important for you (or if you are just curious), do a
benchmark to find out.

perldoc Benchmark

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      01-18-2005
Dinko Korunic <(E-Mail Removed)> wrote:

> Is it possible to use hash slices with multi-dimensional hashes



Yes.


> (and
> how)?



The way it says to in perlreftut.pod.

I like to apply "Use Rule 1" in 3 steps:

@slice_me{ 'foo', 'bar' } # pretend it is a plain hash

@{ }{ 'foo', 'bar' } # replace the name with a block ...

@{ $inner{baz} }{ 'foo', 'bar' } # ... that returns the
# proper kind of reference

> If yes, would hash slices be in any way faster



use Benchmark;


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
scalar and hash slices -- is it supposed to work this way? Richard Harman Perl Misc 8 09-24-2005 03:26 PM
Hash slices Gyruss Perl Misc 1 10-25-2004 01:01 PM
array slices proudfeet VHDL 1 10-01-2003 08:55 AM



Advertisments