Re: map vs foreach

2014-10-01 Thread Andy Bach
you want to iterate with side-effects, then you should use a proper for or foreach loop. Somewhere there's a quote (possibly apocryphal but wait! [2]) from Larry Wall on a map vs foreach thread: "That being said, I'd never grep someone in a void context myself." He actually wasn

Re: map vs foreach

2014-09-30 Thread Shawn H Corey
On Tue, 30 Sep 2014 16:38:24 -0700 SSC_perl wrote: > On Sep 30, 2014, at 4:08 PM, Shawn H Corey wrote: > > code like you will have to read it after an all-night party > > (some day, you will). > > Those days are over, but point taken! ;) They're never over but they do get farther apart.

Re: map vs foreach

2014-09-30 Thread Uri Guttman
On 09/30/2014 05:08 PM, SSC_perl wrote: Is the output of these two lines equivalent? map { $hash->{$_} = shift @record } @{$self->{'FIELDNAMES'}}; $hash->{$_} = shift @record foreach @{$self->{'FIELDNAMES'}}; They appear to be in my testing, but I'd like to make sure.

Re: map vs foreach

2014-09-30 Thread SSC_perl
On Sep 30, 2014, at 4:19 PM, David Precious wrote: > So, e.g.: > > my %fields = map { $_ => shift @record } @{$self->{'FIELDNAMES'}}; > > ... would make sense, because you're using map to produce the data you > want, rather than using it instead of a for loop. Thanks, David. That was an

Re: map vs foreach

2014-09-30 Thread SSC_perl
On Sep 30, 2014, at 4:08 PM, Shawn H Corey wrote: > code like you will have to read it after an all-night party > (some day, you will). Those days are over, but point taken! ;) Thanks, Frank SurfShopCART https://github.com/surfshopcart/surfshop -- To unsubscribe, e-mail: beginners-uns

Re: map vs foreach

2014-09-30 Thread David Precious
On Tue, 30 Sep 2014 14:08:14 -0700 SSC_perl wrote: > Is the output of these two lines equivalent? > > map { $hash->{$_} = shift @record } @{$self->{'FIELDNAMES'}}; > > $hash->{$_} = shift @record foreach @{$self->{'FIELDNAMES'}}; [...] > Is one more appropriate than the other in a s

Re: map vs foreach

2014-09-30 Thread Shawn H Corey
On Tue, 30 Sep 2014 14:08:14 -0700 SSC_perl wrote: > Is the output of these two lines equivalent? > > map { $hash->{$_} = shift @record } @{$self->{'FIELDNAMES'}}; > > $hash->{$_} = shift @record foreach @{$self->{'FIELDNAMES'}}; > > They appear to be in my testing, but I'd like to

Re: map vs foreach

2014-09-30 Thread Omega -1911
Is asking a preference-based question appropriate for a beginners list appropriate? Question for you: Have you updated your software to have a more modern look and feel or does it still resemble 1995? I ask because, in your own words, you said "or is it simply a styling difference?". Feedback for

map vs foreach

2014-09-30 Thread SSC_perl
Is the output of these two lines equivalent? map { $hash->{$_} = shift @record } @{$self->{'FIELDNAMES'}}; $hash->{$_} = shift @record foreach @{$self->{'FIELDNAMES'}}; They appear to be in my testing, but I'd like to make sure. Is one more appropriate than the other in

Re: odd benchmark result, map vs foreach

2005-08-26 Thread Wiggins d'Anconia
then autovivifying >> it. It isn't necessarily the map vs. foreach that is causing your >> difference. I think for your benchmark to be accurate you are going to >> have to control the actions taken in the loop, otherwise they affect the >> accuracy of your benchmark. > >

Re: odd benchmark result, map vs foreach

2005-08-26 Thread Scott R. Godin
Wiggins d'Anconia wrote: Your benchmark isn't controlled. In the first instance you are doing a ++ on what amounts to a scalar getting autovivified, in the second instance you are assigning a pair of values to a list then autovivifying it. It isn't necessarily the map vs.

Re: odd benchmark result, map vs foreach

2005-08-26 Thread Scott R. Godin
John W. Krahn wrote: Scott R. Godin wrote: Interesting .. I would have thought that map would be faster, but it appears that foreach is, in this instance. curious.. :) [snip] To be equivalent the foreach sub should use assignment instead of postincrement (which is also faster.) Interest

Re: odd benchmark result, map vs foreach

2005-08-24 Thread John W. Krahn
Scott R. Godin wrote: > Interesting .. I would have thought that map would be faster, but it > appears that foreach is, in this instance. curious.. :) > > > 4:52pm {193} localhost:/home/webadmin/>$ perl bench.pl > Benchmark: running Foreach, Map for at least 5 CPU seconds... >Foreach: 9 wall

Re: odd benchmark result, map vs foreach

2005-08-24 Thread Wijnand Wiersma
And don't run the two test too soon after eachother, your operating system will cache some data. Also run all the tests multiple times. Wijnand -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: odd benchmark result, map vs foreach

2005-08-24 Thread Wiggins d'Anconia
e_bill_ship rkh_quantity rkp_quantity rmh_quantity > rmp_quantity rbh_quantity rbp_quantity ship_on_account > shipping_id_number order_number }; > }, } > ); > Your benchmark isn't controlled. In the first instance you are doing a ++ on what amounts to a scalar getting autov

odd benchmark result, map vs foreach

2005-08-24 Thread Scott R. Godin
Interesting .. I would have thought that map would be faster, but it appears that foreach is, in this instance. curious.. :) 4:52pm {193} localhost:/home/webadmin/>$ perl bench.pl Benchmark: running Foreach, Map for at least 5 CPU seconds... Foreach: 9 wallclock secs ( 5.24 usr + 0

Re: map vs foreach

2004-11-29 Thread Jonathan Paton
Dear Michael, I am wrong. [SHAME] The output of Benchmark is slowest first... whereas I intuitively thought it would be fastest first. All my conclusions are therefore wrong, although the differences in speed are still surprising. Results may change depending on the version of Perl, I am using

RE: map vs foreach

2004-11-28 Thread Michael Kraus
Thanks heaps Jonathon and Paul for your help. :) Regards, Michael S. E. Kraus Software Developer Wild Technology Pty Ltd ___ ABN 98 091 470 692 Level 4 Tiara, 306/9 Crystal Street, Waterloo NSW 2017, Australia Telephone 1300-13-9453 | Facsimile 1300-88-9453 http://w

Re: map vs foreach

2004-11-28 Thread Jonathan Paton
Dear Michael, None of the above. All your code is calling length() twice per loop. The best way to write what you want is: my $max_length = 0; for my $datum (keys %data) { my $length = length $datum; if ($max_length < $length) { $max_l

Re: map vs foreach

2004-11-28 Thread Paul Johnson
On Mon, Nov 29, 2004 at 10:15:52AM +1100, Michael Kraus wrote: > Which is better to use, a for/foreach loop or map function when doing > some basic comparisons and assignments? > > E.g. > > for my $datum (keys %{$rh_vars}) { > $max_length = length($datum) if length($datum) > $max_length; >

map vs foreach

2004-11-28 Thread Michael Kraus
G'day... Which is better to use, a for/foreach loop or map function when doing some basic comparisons and assignments? E.g. for my $datum (keys %{$rh_vars}) { $max_length = length($datum) if length($datum) > $max_length; } OR map { $max_length = ($max_length > length($_) ? $max_length