Re: map vs foreach

2014-10-01 Thread Andy Bach
On Tue, Sep 30, 2014 at 6:19 PM, David Precious wrote: > Like most things, TIMTOWTDI, but I believe Perl Best Practices [PBP] > advises > against using map in void context. > As PBP[1] is encoded in Perl::Critic map and grep are intended to be pure functions, not mutators. If you want to iterate

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

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