Re: hash slice??

2008-11-10 Thread Rob Dixon
Travis Thornhill wrote: > > Is there such a thing? > > I'm trying to take a HoH and make a reference to a sub-part of the hash. > > This doesn't work: > > my %sub_hash = $main_hash{'sub_hash'}; > > I get the following error: > Reference found where even-sized list expected at ./my_buggy_pro

Re: hash slice??

2008-11-10 Thread John W. Krahn
Travis Thornhill wrote: Is there such a thing? Yes there is. I'm trying to take a HoH and make a reference to a sub-part of the hash. This doesn't work: my %sub_hash = $main_hash{'sub_hash'}; I get the following error: Reference found where even-sized list expected at ./my_buggy_program li

Re: hash slice??

2008-11-10 Thread Rob Coops
On Mon, Nov 10, 2008 at 3:52 PM, Travis Thornhill <[EMAIL PROTECTED] > wrote: > Is there such a thing? > > I'm trying to take a HoH and make a reference to a sub-part of the hash. > > This doesn't work: > > my %sub_hash = $main_hash{'sub_hash'}; > > I get the following error: > Reference found whe

Re: hash slice??

2008-11-10 Thread Chas. Owens
On Mon, Nov 10, 2008 at 09:52, Travis Thornhill <[EMAIL PROTECTED]> wrote: > Is there such a thing? > > I'm trying to take a HoH and make a reference to a sub-part of the hash. > > This doesn't work: > > my %sub_hash = $main_hash{'sub_hash'}; > > I get the following error: > Reference found where e

Re: Hash slice

2007-11-12 Thread Jenda Krynicky
From: "Beginner" <[EMAIL PROTECTED]> > On 9 Nov 2007 at 20:04, Jenda Krynicky wrote: > > @[EMAIL PROTECTED] = map [$valone[$_], $valtwo[$_]] (0..$#valone); > > > > > > The map produces a list of arrayrefs, each referenced array contains > > one item from @valone and one from @va

Re: Hash slice

2007-11-12 Thread Beginner
On 9 Nov 2007 at 20:04, Jenda Krynicky wrote: > From: "Beginner" <[EMAIL PROTECTED]> > > On 9 Nov 2007 at 16:35, Jenda Krynicky wrote: > > > > > From: "Beginner" <[EMAIL PROTECTED]> > > > > #!/bin/perl > > > > > > > > use strict; > > > > use warnings; > > > > use Data::Dumper; > > > > > > > > m

Re: Hash slice

2007-11-09 Thread Jenda Krynicky
From: "Beginner" <[EMAIL PROTECTED]> > On 9 Nov 2007 at 16:35, Jenda Krynicky wrote: > > > From: "Beginner" <[EMAIL PROTECTED]> > > > #!/bin/perl > > > > > > use strict; > > > use warnings; > > > use Data::Dumper; > > > > > > my @keys = qw(fe fi fo thumb); > > > my @valone = 1..4; > > > my @valt

Re: Hash slice

2007-11-09 Thread Paul Lalli
On Nov 9, 11:09 am, [EMAIL PROTECTED] (Beginner) wrote: > What I was attempting was to have each key to be assigned the > coresponding items from the array. Why didn't you just say that in the first place, rather than letting everyone guess as to what you wanted? > So it might look like something

Re: Hash slice

2007-11-09 Thread Rob Dixon
Beginner wrote: On 9 Nov 2007 at 14:59, Rob Dixon wrote: Beginner wrote: Is it possible to make a hash slice like so It's certainly possible, but I'm not sure why you've taken a reference to your key and value arrays. [EMAIL PROTECTED] is a single scalar value, as is [EMAIL PROTECTED], so

Re: Hash slice

2007-11-09 Thread [EMAIL PROTECTED]
On Nov 9, 4:09 pm, [EMAIL PROTECTED] (Beginner) wrote: > On 9 Nov 2007 at 16:35, Jenda Krynicky wrote: > > What I was attempting was to have each key to be assigned the > coresponding items from the array. So it might look like something > like: Right, so your question has nothing to do with hash

Re: Hash slice

2007-11-09 Thread [EMAIL PROTECTED]
On Nov 9, 3:35 pm, [EMAIL PROTECTED] (Jenda Krynicky) wrote: > > @[EMAIL PROTECTED] = ( [EMAIL PROTECTED],[EMAIL PROTECTED]); Note that _can_ also be written @[EMAIL PROTECTED] = \( @valone, @valtwo); But IMNSHO it this syntax should _only_ be used in code that is intended as part of a respon

Re: Hash slice

2007-11-09 Thread Beginner
On 9 Nov 2007 at 16:35, Jenda Krynicky wrote: > From: "Beginner" <[EMAIL PROTECTED]> > > #!/bin/perl > > > > use strict; > > use warnings; > > use Data::Dumper; > > > > my @keys = qw(fe fi fo thumb); > > my @valone = 1..4; > > my @valtwo = 10..14; > > my %hash; > > @[EMAIL PROTECTED] = [EMAIL PR

Re: Hash slice

2007-11-09 Thread Beginner
On 9 Nov 2007 at 14:59, Rob Dixon wrote: > Beginner wrote: > > Hi all, > > > > Is it possible to make a hash slice like so > Hey Dermot Hi Rob, > It's certainly possible, but I'm not sure why you've taken a reference > to your key and value arrays. [EMAIL PROTECTED] is a single scalar value,

Re: Hash slice

2007-11-09 Thread Jenda Krynicky
From: "Beginner" <[EMAIL PROTECTED]> > #!/bin/perl > > use strict; > use warnings; > use Data::Dumper; > > my @keys = qw(fe fi fo thumb); > my @valone = 1..4; > my @valtwo = 10..14; > my %hash; > @[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo]; [...] creates an array reference. You want @[EM

Re: Hash slice

2007-11-09 Thread Rob Dixon
Beginner wrote: Hi all, Is it possible to make a hash slice like so my %hash; @[EMAIL PROTECTED] = [EMAIL PROTECTED]; My efforts suggest not: #!/bin/perl use strict; use warnings; use Data::Dumper; my @keys = qw(fe fi fo thumb); my @vals = 1..4; my %hash; @[EMAIL PROTECTED] = [EMAIL PROTECT

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-26 Thread JupiterHost.Net
renard wrote: BE AWARE THAT THE BENCHMARK PROVIDES INCORRECT RESULTS. Thnaks, I was aware of that, but still wanted a general idea :) The tested code is within an anonymous subroutine while this does executes, the results differ dramitcally from the results when the tested code is enclosed withi

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-26 Thread JupiterHost.Net
The slice version took about 10 seconds, the grep one took more than 1 minute. Marcello Thanks Marcello! Your example, John's. and renards have been very helpful to help see the point someone else was trying to make about watching what you include in your benchmark. I appreciate your time :)

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-26 Thread Marcello
JupiterHost.Net ha scritto: In benchmarking some code I've come across something I did not expect: slice: use strict; use warnings; my @k=qw(1 2 3 4 5 6); my %n;@[EMAIL PROTECTED] = @k; print "hi" if exists $n{1}; print "hi" if exists $n{3}; print "hi" if exists $n{5}; print "hi" if exists $n{7}; p

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
> Lawrence Statton wrote: [snip] Gotcha, thx So then can you suggest a method of benchmarking these 2 methods that would be more accurate? I believe John's solution was excellent at illustrating th deficiencies in the way I was doing it and supplying a solution and answering my question all at

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
#!/usr/bin/perl use warnings; use strict; use Benchmark 'cmpthese'; my @k = qw( 1 2 3 4 5 6 ); cmpthese( -10, { exists => sub { my $count = 0; my %hash; @hash{ @k } = (); for my $num ( 1, 3, 5, 7, 9, 11 ) { $count++ if exists $hash{ $num };

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread John W. Krahn
JupiterHost.Net wrote: In benchmarking some code I've come across something I did not expect: slice: use strict; use warnings; my @k=qw(1 2 3 4 5 6); my %n;@[EMAIL PROTECTED] = @k; print "hi" if exists $n{1}; print "hi" if exists $n{3}; print "hi" if exists $n{5}; print "hi" if exists $n{7}; print

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread Lawrence Statton
> Thanks for your input :) No problem -- I really do enjoy this. However, I do have some actual WORK that I need to do today :( > > Finally, there were serious errors in your methodology in your > > Serious? I thought "in the Big Picture, it won't matter a gnats eyebrow." :) And I stand by t

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
Thanks for your input :) Finally, there were serious errors in your methodology in your Serious? I thought "in the Big Picture, it won't matter a gnats eyebrow." :) original benchmark. It turns out the printing dominated the total That is why I made both identical except for the difference I'm co

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
Bakken, Luke wrote: You have to stop spending so much time playing with all this bogus benchmarking :) It not bogus :) Its an example to find the best method for a project. If you prefer I'll ask the question I was trying to answer with the benchmark: Assuming you have an array of 0-15 elements

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
print "hi" if $n{11}; What if it's value is 0, '', or undef? It would exist but your test would miss it :) In that case "defined" would be a beter function to use. ok, but I'm still not interested in the value of the key I;'m interested inthe key, so why not exists since its made for hashes :)

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread Lawrence Statton
> > You have to stop spending so much time playing with all this bogus > > benchmarking :) > > It not bogus :) Its an example to find the best method for a project. > And I'll reiterate more clearly. Benchmarking is *not* the tool to find the best method. The BEST method for a project is that

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread mgoland
- Original Message - From: "JupiterHost.Net" <[EMAIL PROTECTED]> Date: Tuesday, January 25, 2005 11:37 am Subject: Re: hash slice/exists vs. grep benchmark weirdness... > > > > > Just as an FYI, you don't need "exists" in your code at all.

RE: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread Bakken, Luke
> > You have to stop spending so much time playing with all this bogus > > benchmarking :) > > It not bogus :) Its an example to find the best method for a project. > > If you prefer I'll ask the question I was trying to answer with the > benchmark: > > Assuming you have an array of 0-15 elemen

RE: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread Thomas Bätzler
[EMAIL PROTECTED] suggested: > Just as an FYI, you don't need "exists" in your code at all. > It is just a waste of time in your example. Should be beter writen as: > > print "hi" if $n{11}; Bad idea, if you consider this: $n{'oops'} = 0; print "hi" if $n{'oops'}; print "ho" if exists $n{'oop

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
Just as an FYI, you don't need "exists" in your code at all. It is just a waste of time in your example. Should be beter writen as: print "hi" if $n{11}; What if it's value is 0, '', or undef? It would exist but your test would miss it :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additio

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread mgoland
- Original Message - From: "JupiterHost.Net" <[EMAIL PROTECTED]> Date: Tuesday, January 25, 2005 11:01 am Subject: Re: hash slice/exists vs. grep benchmark weirdness... > > You have to stop spending so much time playing with all this bogus > > benchmarking :)

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-25 Thread JupiterHost.Net
You have to stop spending so much time playing with all this bogus benchmarking :) It not bogus :) Its an example to find the best method for a project. If you prefer I'll ask the question I was trying to answer with the benchmark: Assuming you have an array of 0-15 elements is it quicker/more ef

Re: hash slice/exists vs. grep benchmark weirdness...

2005-01-24 Thread Lawrence Statton
> In benchmarking some code I've come across something I did not expect: > You have to stop spending so much time playing with all this bogus benchmarking :) > slice: > use strict; > use warnings; > my @k=qw(1 2 3 4 5 6); > my %n;@[EMAIL PROTECTED] = @k; > print "hi" if exists $n{1}; > print "h