Re: What are these numbers (gmtime, slice)

2019-07-08 Thread Uri Guttman
the args list to builtins. it eliminates funny arg parsing and also shows to the reader there is a function call with no args. it would have caught the error as:     gmtime()[1..5] should be a syntax error (didn't check). also a better way to slice out gmtime is to assign it to an list o

Re: What are these numbers (gmtime, slice)

2019-07-08 Thread Mike Small
Uri Guttman writes: > On 7/4/19 2:41 PM, Mike Small wrote: >> A co-worker was trying to take some of the elements from gmtime's return >> value. He did something like the following: >> >> $ perl -E'$,="\t";say gmtime[1..5]' > > that is calling gmtime with the argument of [1..5] which is an >

Re: What are these numbers (gmtime, slice)

2019-07-07 Thread Uri Guttman
On 7/4/19 2:41 PM, Mike Small wrote: A co-worker was trying to take some of the elements from gmtime's return value. He did something like the following: $ perl -E'$,="\t";say gmtime[1..5]' that is calling gmtime with the argument of [1..5] which is an arrayref. so the arg to gmtime is some

What are these numbers (gmtime, slice)

2019-07-07 Thread Mike Small
A co-worker was trying to take some of the elements from gmtime's return value. He did something like the following: $ perl -E'$,="\t";say gmtime[1..5]' 8 32 12 31 7 2999416 1 243 0 I suggested he try something like this instead... $ perl -E'$,="\t";say

Fwd: slice of an arrayref

2010-10-29 Thread shawn wilson
many to many problem i noted above). my issue is how to print out a slice of an arrayref of a hashref? my underlying problem (i think) is that there has got to be a better way? i've got half a mind to create a temp table in the db to do this, but that doesn't seem like my 'better way' either. thanks

Slice?

2009-03-16 Thread R. Hicks
$template-param( RESULTS = $self-dbh-selectall_arrayref(' SELECT age, day FROM table WHERE id = ?', { Slice = {} }, $self-session-param('cell')-{'sid'} ) ); I saw that code and while I do database stuff I was wondering what that Slice = {} does? Thanks, Robert

Re: Slice?

2009-03-16 Thread Jim Gibson
On 3/16/09 Mon Mar 16, 2009 3:05 PM, R. Hicks sigz...@gmail.com scribbled: $template-param( RESULTS = $self-dbh-selectall_arrayref(' SELECT age, day FROM table WHERE id = ?', { Slice = {} }, $self-session-param('cell')-{'sid'} ) ); I saw that code and while I do

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-14 Thread Chas. Owens
On Sat, Mar 14, 2009 at 01:06, Chap Harrison c...@pobox.com wrote: On Mar 13, 2009, at 7:52 AM, Jenda Krynicky wrote: That's prettymuch it, except that it's not an array of aliases, but LIST of aliases. The difference is subtle, but important. See

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-13 Thread Jenda Krynicky
From: Chap Harrison c...@pobox.com Let me break this expression down according to my current understanding. @{$hash{adams...@keys} = @values; parses as follows: adams : short for 'adams', a string literal, being used as a hash key $hash{adams} : the value in the hash

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-13 Thread Chap Harrison
On Mar 13, 2009, at 7:52 AM, Jenda Krynicky wrote: That's prettymuch it, except that it's not an array of aliases, but LIST of aliases. The difference is subtle, but important. See http://perldoc.perl.org/perlfaq4.html#What-is-the-difference- between-a-list-and-an-array%3f and

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-12 Thread Chap Harrison
On Mar 12, 2009, at 12:52 AM, Chas. Owens wrote: On Thu, Mar 12, 2009 at 01:27, Chap Harrison c...@pobox.com wrote: It's still not intuitive to me why we FIRST convert the hash to an array, and THEN ask for keys - keys being hash-ish, rather than array-ish sorts of things. (I've said

Assigning an array to a dereferenced hash slice - syntax!

2009-03-11 Thread Chap Harrison
', 'aw' ); my @values = ( 1, 19, 13, 11); # # The following is trying to assign an array to a hash slice. # (courtesy http://www.perlmonks.org/?node_id=4402, who did a simpler # version that did not involve references.) # @{{$hashref}-{...@keys}} = @values;# don't know if this is right

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-11 Thread Chas. Owens
= $schoolprops{Adams}; # create a ref to a hash. my @keys = ( 'a', 'ar', 'af', 'aw' ); my @values = ( 1, 19, 13, 11); # # The following is trying to assign an array to a hash slice. # (courtesy http://www.perlmonks.org/?node_id=4402, who did a simpler # version that did not involve references

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-11 Thread Chap Harrison
On Mar 11, 2009, at 11:51 PM, Chas. Owens wrote: Dereference the hashref as an arrayref then ask for the keys: #!/usr/bin/perl use strict; use warnings; my %hash = ( adams = {} ); my @keys = qw/a ar af aw/; my @values = (1, 19, 13, 11); @{$hash{adams...@keys} = @values; use

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-11 Thread John W. Krahn
to a reference to an empty hash. my $hashref = $schoolprops{Adams}; # create a ref to a hash. It doesn't create it, it just copies it. my @keys = ( 'a', 'ar', 'af', 'aw' ); my @values = ( 1, 19, 13, 11); # # The following is trying to assign an array to a hash slice. # (courtesy http

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-11 Thread John W. Krahn
that badly.) What exactly are the elements of the array @{$hash{adams...@keys} ? @{$hash{adams...@keys} is *not* an array, it is a hash slice. John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners

Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-11 Thread Chas. Owens
On Thu, Mar 12, 2009 at 01:27, Chap Harrison c...@pobox.com wrote: On Mar 11, 2009, at 11:51 PM, Chas. Owens wrote: Dereference the hashref as an arrayref then ask for the keys: #!/usr/bin/perl use strict; use warnings; my %hash = ( adams = {} ); my @keys   = qw/a ar af aw/; my

hash slice??

2008-11-10 Thread Travis Thornhill
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_program line 30.   Any quick tips on how to

Re: hash slice??

2008-11-10 Thread Chas. Owens
, six = 6 ); #get keys whose values are odd my @keys = grep { $name_to_num{$_} % 2 } keys %name_to_num; #make a hash of the odd keys and values with a hash slice my %odd_name_to_num; @[EMAIL PROTECTED] = @[EMAIL PROTECTED]; print Dumper \%name_to_num, \%odd_name_to_num; -- Chas. Owens

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 where

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

Re: hash slice??

2008-11-10 Thread Rob Dixon
30. Any quick tips on how to reference and assign this sub-hash? There is certainly such a thing as a hash slice, but I think it is probably not what you want here. A slice will let you extract multiple values from the hash simultaneously, something like my @subhashes = @main_hash{'key1

Issue with references and array slice with one member !

2008-10-31 Thread Amit Saxena
Hello all, Recently I faced one scenario with references and array slice in perl. I used following program to retrieve the rows from a table in Oracle using Perl DBI. As shown in the program, I did following steps to retrieve the rows :- - used fetchall_arrayref to get the array reference

Re: Issue with references and array slice with one member !

2008-10-31 Thread Chas. Owens
of them were same. When I did a through debugging on this, I found that @{$row}[0] or @{$row}[1] etc is taken as array slice by perl with only one member so it returns the value of the column in scalar and not in list context. With ${$row}[0] or ${$row}[1] etc, the column value is returned

Re: populating a hash slice from a filehandle

2008-06-23 Thread Jay Savage
to populate @l2r{a,b}, it seems to me that it would go through this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list and assign it to $l2r{a} - The second is b, so I'll pull another scalar off the list and assign it to $l2r

Re: populating a hash slice from a filehandle

2008-06-23 Thread Bryan R Harris
to me that it would go through this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list and assign it to $l2r{a} - The second is b, so I'll pull another scalar off the list and assign it to $l2r{b} - Remaining scalars

Re: populating a hash slice from a filehandle

2008-06-23 Thread Jenda Krynicky
From:Bryan R Harris [EMAIL PROTECTED] Jenda wrote: From: Bryan R Harris [EMAIL PROTECTED] It makes more sense to me that (FILE,FILE) is kind of the same thing as saying (@a,@b). In list context @a returns the array as a list, but in scalar context @a returns the number of elements.

Re: populating a hash slice from a filehandle

2008-06-21 Thread Jenda Krynicky
}, it seems to me that it would go through this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list and assign it to $l2r{a} - The second is b, so I'll pull another scalar off the list and assign it to $l2r{b

Re: populating a hash slice from a filehandle

2008-06-20 Thread Bryan R Harris
{...} part? The left hand side of the assignment determines context so the @l2r{...} part. That strikes me as odd... When perl goes to populate @l2r{a,b}, it seems to me that it would go through this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll

Re: populating a hash slice from a filehandle

2008-06-20 Thread John W. Krahn
: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list and assign it to $l2r{a} - The second is b, so I'll pull another scalar off the list and assign it to $l2r{b} - Remaining scalars in the list are discarded Correct, except for the loop

Re: populating a hash slice from a filehandle

2008-06-20 Thread Bryan R Harris
this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list and assign it to $l2r{a} - The second is b, so I'll pull another scalar off the list and assign it to $l2r{b} - Remaining scalars in the list are discarded Correct, except

Re: populating a hash slice from a filehandle

2008-06-19 Thread Bryan R Harris
From: Bryan R Harris [EMAIL PROTECTED] Given an open filehandle, why don't these two things do the same thing? ** @l2r{a,b} = (FILE, FILE); $c = FILE; ** $l2r{a} = FILE; $l2r{b} = FILE; $c = FILE;

Re: populating a hash slice from a filehandle

2008-06-19 Thread John W. Krahn
Bryan R Harris wrote: From: Bryan R Harris [EMAIL PROTECTED] Given an open filehandle, why don't these two things do the same thing? ** @l2r{a,b} = (FILE, FILE); $c = FILE; ** $l2r{a} = FILE; $l2r{b} = FILE; $c = FILE;

Re: populating a hash slice from a filehandle

2008-06-19 Thread Bryan R Harris
this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list and assign it to $l2r{a} - The second is b, so I'll pull another scalar off the list and assign it to $l2r{b} - Remaining scalars in the list are discarded Why would $l2r

Re: populating a hash slice from a filehandle

2008-06-19 Thread John W. Krahn
side of the assignment determines context so the @l2r{...} part. That strikes me as odd... When perl goes to populate @l2r{a,b}, it seems to me that it would go through this process: - I have a slice here, so I'll loop over the slice elements - The first is a, so I'll pull a scalar off the list

populating a hash slice from a filehandle

2008-06-18 Thread Bryan R Harris
Given an open filehandle, why don't these two things do the same thing? ** @l2r{a,b} = (FILE, FILE); $c = FILE; ** $l2r{a} = FILE; $l2r{b} = FILE; $c = FILE; ** The first seems to be

Re: populating a hash slice from a filehandle

2008-06-18 Thread Jeff Peng
On Thu, Jun 19, 2008 at 5:50 AM, Bryan R Harris [EMAIL PROTECTED] wrote: Given an open filehandle, why don't these two things do the same thing? ** @l2r{a,b} = (FILE, FILE); $c = FILE; because @l2r{...} is a list, right? so the statement above is in a

Re: populating a hash slice from a filehandle

2008-06-18 Thread Jenda Krynicky
From: Bryan R Harris [EMAIL PROTECTED] Given an open filehandle, why don't these two things do the same thing? ** @l2r{a,b} = (FILE, FILE); $c = FILE; ** $l2r{a} = FILE; $l2r{b} = FILE; $c = FILE;

Re: split slice question

2008-05-11 Thread Dr.Ruud
Richard Lee schreef: I use this before (split slice ) but it's working bit funny now.. it looks like it's splitting on '' instead of /|/ as I have specified below... ?? Look for quotemeta in perlre. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED

split slice question

2008-05-10 Thread Richard Lee
I use this before (split slice ) but it's working bit funny now.. can someone tell me why?? it looks like it's splitting on '' instead of /|/ as I have specified below... ?? use strict; use warnings; my $array = q/hi|how|are|you|fine/; my ($moe,$hae,$now) = (split(/|/,$array))[0,1,2

Re: split slice question

2008-05-10 Thread Gunnar Hjalmarsson
Richard Lee wrote: my ($moe,$hae,$now) = (split(/|/,$array))[0,1,2]; '|' is special in a regular expression and needs to be escaped. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL

Re: Hash slice

2007-11-12 Thread Beginner
was trying to achieve. I typed out the output from Dumper I was expecting because I was/am not entirely sure what terms to use. The above operation looks like a hash slice to me albeit with another operator (map) involved. Thanx for the help. Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED

Re: Hash slice

2007-11-12 Thread Jenda Krynicky
of confusion over what I was trying to achieve. I typed out the output from Dumper I was expecting because I was/am not entirely sure what terms to use. The above operation looks like a hash slice to me albeit with another operator (map) involved. Yep, the Dumper output was exactly the right thing

Hash slice

2007-11-09 Thread Beginner
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 PROTECTED]; print

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

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 @[EMAIL PROTECTED]

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 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 PROTECTED],@valtwo];

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

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

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 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 @valtwo = 10..14; my %hash; @[EMAIL

Re: hashref ref ref slice

2006-05-03 Thread Karjala
Try this: map {$_-{text}} @[EMAIL PROTECTED] Ryan Perry wrote: @[EMAIL PROTECTED]{text} I want to get all the text values for a set of keys in a hashref, but the above code always gives me only the first in @sortedkeys. Thanks for any assistance! Ryan --To unsubscribe, e-mail: [EMAIL

Re: hashref ref ref slice

2006-05-03 Thread Karjala
And this will work also: map {$tmp-{$_}-{text}} @sortedkeys Karjala wrote: Try this: map {$_-{text}} @[EMAIL PROTECTED] Ryan Perry wrote: @[EMAIL PROTECTED]{text} I want to get all the text values for a set of keys in a hashref, but the above code always gives me only the first in

hashref ref ref slice

2006-05-02 Thread Ryan Perry
@[EMAIL PROTECTED]{text} I want to get all the text values for a set of keys in a hashref, but the above code always gives me only the first in @sortedkeys. Thanks for any assistance! Ryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

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}; print hi

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 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

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

2005-01-25 Thread JupiterHost.Net
efficient to: 1) create a hash slice and use exists when checking for specific ones or 2) grep a regex out of the array when checking for specific ones 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

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 :) It not bogus :) Its an example

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 additional

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{'oops'}; HTH,

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

2005-01-25 Thread Bakken, Luke
is it quicker/more efficient to: 1) create a hash slice and use exists when checking for specific ones or 2) grep a regex out of the array when checking for specific ones If you're going to be looking for something in an array over and over again, perhaps you shouldn't be using an array

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. It is just a waste of time in your example. Should

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

2005-01-25 Thread Lawrence Statton
the question I was trying to answer with the benchmark: Assuming you have an array of 0-15 elements is it quicker/more efficient to: 1) create a hash slice and use exists when checking for specific ones or 2) grep a regex out of the array when checking for specific ones Both. Each

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

2005-01-25 Thread JupiterHost.Net
simply asked what if to illustrate why if $n{11} is not better than exists $n{11} in this case. So the original question remains: Which is faster: 1) slice the array into a has and do exists $hsh{key} or 2) just grep a regex on the array -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional

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

2005-01-25 Thread JupiterHost.Net
is it quicker/more efficient to: 1) create a hash slice and use exists when checking for specific ones or 2) grep a regex out of the array when checking for specific ones If you're going to be looking for something in an array over and over again, perhaps you shouldn't be using an array

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

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 that

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 hi

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 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

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

2005-01-24 Thread JupiterHost.Net
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 hi if exists $n{9}; print hi

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 hi if exists

How to slice a split directly?

2004-09-23 Thread Siegfried Heintze
This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? Thanks

Re: How to slice a split directly?

2004-09-23 Thread William Gunther
, it returns a list. print( (split(/\./, a.b.c))[0] ); Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? Thanks, Siegfried -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail

Re: How to slice a split directly?

2004-09-23 Thread Jenda Krynicky
From: Siegfried Heintze [EMAIL PROTECTED] This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array

Re: How to slice a split directly?

2004-09-23 Thread Wiggins d Anconia
This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable

Re: How to slice a split directly?

2004-09-23 Thread Jenda Krynicky
From: Wiggins d Anconia [EMAIL PROTECTED] This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns

slice and dice them

2003-09-30 Thread SilverFox
can anyone tell me how I can remove the period at the end of each line below?? . . . . -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: slice and dice them

2003-09-30 Thread James Edward Gray II
On Monday, September 29, 2003, at 10:53 AM, SilverFox wrote: can anyone tell me how I can remove the period at the end of each line below?? Sure. Place your cursor at the end of each line in turn and push the backspace (or similar key) once... Oh, did you mean in Perl? ;) What part are you

RE: slice and dice them

2003-09-30 Thread Wiggins d'Anconia
On Mon, 29 Sep 2003 11:53:16 -0400, SilverFox [EMAIL PROTECTED] wrote: can anyone tell me how I can remove the period at the end of each line below?? . . . . Let's see if I can start a flame war ;-)... perldoc -f chop

Re: slice indexing

2003-01-13 Thread Bryan Harris
I need to slice an array such that it gives me the first through the 4th to last in a variable length array. I thought I could just do: @comments[0..-4] but Perl seems to choke on this. It's perfectly okay with a slice using two negative #s: @comments[-2..-4] Anyone know why

slice indexing

2003-01-12 Thread Bryan Harris
I need to slice an array such that it gives me the first through the 4th to last in a variable length array. I thought I could just do: @comments[0..-4] but Perl seems to choke on this. It's perfectly okay with a slice using two negative #s: @comments[-2..-4] Anyone know why it doesn't

Re: slice indexing

2003-01-12 Thread John W. Krahn
Bryan Harris wrote: I need to slice an array such that it gives me the first through the 4th to last in a variable length array. I thought I could just do: @comments[0..-4] but Perl seems to choke on this. It's perfectly okay with a slice using two negative #s: @comments[-2..-4

Re: slice indexing

2003-01-12 Thread Rob Dixon
Rob Dixon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Hi Bryan Bryan Harris [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I need to slice an array such that it gives me the first through the 4th to last in a variable length a

slice indexing

2003-01-12 Thread Bryan Harris
I need to slice an array such that it gives me the first through the 4th to last in a variable length array. I thought I could just do: @comments[0..-4] but Perl seems to choke on this. It's perfectly okay with a slice using two negative #s: @comments[-2..-4] Anyone know why it doesn't

RE: Obtaining a slice of unique values from an array

2002-07-01 Thread Shishir K. Singh
on Sun, 30 Jun 2002 12:08:23 GMT, Dan Fish wrote: What is the most efficient (or at least AN efficient :-) way of obtaining a slice from an array wherein the slice contains only unique values found in the array? See perldoc -q duplicate -- felix This is the example d cited

Obtaining a slice of unique values from an array

2002-06-30 Thread Dan Fish
What is the most efficient (or at least AN efficient :-) way of obtaining a slice from an array wherein the slice contains only unique values found in the array? I.E. if @array = (1,3,5,5,3,5,2,1) then @slice = (1,3,5,2) Thanks, -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED

array slice syntax

2001-11-03 Thread Thomas Hofer
Hi! As a perl beginner, I have a silly question about array-slices-syntax: That's clear: perl -e '@a=(a,b,c);print @a[1..2]\n' == b c perl -e '@a=(a,b,c);print $a[1]\n' == b But why does $array[range] always give the first array-entry? perl -e '@a=(a,b,c);print $a[1..2]\n' == a (OK, maybe

Re: array slice syntax

2001-11-03 Thread Paul Johnson
On Sat, Nov 03, 2001 at 05:49:37PM +0100, Thomas Hofer wrote: Hi! As a perl beginner, I have a silly question about array-slices-syntax: That's clear: perl -e '@a=(a,b,c);print @a[1..2]\n' == b c perl -e '@a=(a,b,c);print $a[1]\n' == b But why does $array[range] always give

create hash slice from hash

2001-10-31 Thread Lisa Neclos
I am attempting to create a hash slice from a hash. The hash is: %hash =(test1 = test10, test2 = test12 , test3 = test13) I want the slice to include only the keys test1 and test3. How can I accomplish this? -- To unsubscribe

Re: create hash slice from hash

2001-10-31 Thread Curtis Poe
--- Lisa Neclos [EMAIL PROTECTED] wrote: I am attempting to create a hash slice from a hash. The hash is: %hash =(test1 = test10, test2 = test12 , test3 = test13) I want the slice to include only the keys test1 and test3

Re: create hash slice from hash

2001-10-31 Thread Daniel Gardner
LN I am attempting to create a hash slice from a hash. The hash is: LN %hash =(test1 = test10, LNtest2 = test12 , LN test3 = test13) LN I want the slice to include only the keys test1 and test3. How can I LN accomplish

array slice question

2001-06-26 Thread Bradford Ritchie
Hi, I have an unnamed array which I created from splitting up a colon separated string: $_ = 0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text: might have :colons: or might not print ((split /:/)[1,6,8]); ...but I really need to print everything after the 8th element. If the

RE: array slice question

2001-06-26 Thread Stephen Nelson
are not field delimiters, but just part of the text. Other than that, you may need to bite the bullet and name the array. -Original Message- From: Bradford Ritchie [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 26, 2001 1:46 PM To: [EMAIL PROTECTED] Subject: array slice question Hi, I

Re: array slice question

2001-06-26 Thread dave hoover
Bradford wrote: Hi, I have an unnamed array which I created from splitting up a colon separated string: $_ = 0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text: might have :colons: or might not print ((split /:/)[1,6,8]); ...but I really need to print everything after

Re: array slice question

2001-06-26 Thread royce . wells
[1,6,8..-1] in this case - is seen as a metacharacter inside the character class and is not seen as -1 Hi, I have an unnamed array which I created from splitting up a colon separated string: $_ = 0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text: might have :colons: or might not

Re: array slice question

2001-06-26 Thread Michael Fowler
, but specifying ... [1,6,8..-1] doesn't work. However, this I will elaborate on. If you think about it you will be able to tell why a slice of [8..-1] doesn't work. The .. operator is not just used in array slicing, it's a more general range operator. What sense does 8 .. -1 make outside of the context

  1   2   >