Re: Map function, what does it do?

2011-01-12 Thread Uri Guttman
> "R" == Ruud writes: R> On 2011-01-12 18:08, Uri Guttman wrote: >> Ruud writes: >>> On 2011-01-11 11:44, Uri Guttman wrote: these are equivilent: my @out = grep /foo/, @in ; my @out = map { /foo/ ? $_ : () } @in ; >>> >>> Indeed equivalent. There is

Re: Map function, what does it do?

2011-01-12 Thread Dr.Ruud
On 2011-01-12 18:08, Uri Guttman wrote: Ruud writes: On 2011-01-11 11:44, Uri Guttman wrote: these are equivilent: my @out = grep /foo/, @in ; my @out = map { /foo/ ? $_ : () } @in ; Indeed equivalent. There is a difference though in what comes out of map and grep: perl -wle'

Re: OT: Map function, what does it do?

2011-01-12 Thread Rob Dixon
On 12/01/2011 17:51, shawn wilson wrote: On Jan 12, 2011 12:10 PM, "Uri Guttman" wrote: "R" == Ruud> writes: R> On 2011-01-11 11:44, Uri Guttman wrote: >> these are equivilent: >> >> my @out = grep /foo/, @in ; >> my @out = map { /foo/ ? $_ : () } @in ; R> Indeed equivale

OT: Map function, what does it do?

2011-01-12 Thread shawn wilson
On Jan 12, 2011 12:10 PM, "Uri Guttman" wrote: > > > "R" == Ruud > writes: > > R> On 2011-01-11 11:44, Uri Guttman wrote: > >> these are equivilent: > >> > >> my @out = grep /foo/, @in ; > >> my @out = map { /foo/ ? $_ : () } @in ; > > R> Indeed equivalent. There is a difference though

Re: Map function, what does it do?

2011-01-12 Thread Uri Guttman
> "R" == Ruud writes: R> On 2011-01-11 11:44, Uri Guttman wrote: >> these are equivilent: >> >> my @out = grep /foo/, @in ; >> my @out = map { /foo/ ? $_ : () } @in ; R> Indeed equivalent. There is a difference though R> in what comes out of map and grep: R> perl -wle' R

Re: Map function, what does it do?

2011-01-12 Thread Dr.Ruud
On 2011-01-11 11:44, Uri Guttman wrote: these are equivilent: my @out = grep /foo/, @in ; my @out = map { /foo/ ? $_ : () } @in ; Indeed equivalent. There is a difference though in what comes out of map and grep: perl -wle' my @in = 1 .. 4; print "@in"; ++$_ for

Re: Map function, what does it do?

2011-01-11 Thread Brian Fraser
Rob, I'm going to answer the middle part of your mail first, hopefully you won't mind: > On Tue, Jan 11, 2011 at 3:56 PM, Rob Dixon wrote: > The link you supply talks about recent versions of push, pop, etc. > working on array references as well as arrays, so that the code could > also be writt

Re: Map function, what does it do?

2011-01-11 Thread Rob Dixon
On 11/01/2011 14:30, Brian Fraser wrote: On Tue, Jan 11, 2011 at 10:19 AM, John W. Krahn wrote: foreach (@arr) { push @new, $_; } Trying to use a scalar as the first argument to push will result in an error message. Doesn't make the original any less wrong, but as an aside, that's no lo

Re: Map function, what does it do?

2011-01-11 Thread Brian Fraser
On Tue, Jan 11, 2011 at 10:19 AM, John W. Krahn wrote: > foreach (@arr) { > push @new, $_; > } > > Trying to use a scalar as the first argument to push will result in an > error message. > > Doesn't make the original any less wrong, but as an aside, that's no longer true on 5.13.7+ Perls. http:/

Re: Map function, what does it do?

2011-01-11 Thread John W. Krahn
shawn wilson wrote: On Tue, Jan 11, 2011 at 4:57 AM, Sean Murphy wrote: Hi all. I have read the explaination of the Map function and it is still a mystry to myself on what it is for and when would you use it? All explainations I have seen in books and blogs don't make it clear. my @new = m

Re: Map function, what does it do?

2011-01-11 Thread shawn wilson
>> that is a poor explanation IMO. hell, i was going to give this which dereferences the reference of a reference DBI's selectall_arrayref returns so that i can later loop through it again and again with different parameters: my (@groups) = map {...@$_} @{ $dbh->selectall_arrayref("select distinc

Re: Map function, what does it do?

2011-01-11 Thread Sean Murphy
- From: "Uri Guttman" To: "shawn wilson" Cc: "Sean Murphy" ; Sent: Tuesday, January 11, 2011 9:44 PM Subject: Re: Map function, what does it do? "sw" == shawn wilson writes: sw> On Tue, Jan 11, 2011 at 4:57 AM, Sean Murphy wrote: >> Hi

Re: Map function, what does it do?

2011-01-11 Thread Uri Guttman
> "sw" == shawn wilson writes: sw> On Tue, Jan 11, 2011 at 4:57 AM, Sean Murphy wrote: >> Hi all. >> >> I have read the explaination of the Map function and it is still a mystry to >> myself on what it is for and when would you use it? >> >> All explainations I have seen in

Re: Map function, what does it do?

2011-01-11 Thread shawn wilson
On Tue, Jan 11, 2011 at 4:57 AM, Sean Murphy wrote: > Hi all. > > I have read the explaination of the Map function and it is still a mystry to > myself on what it is for and when would you use it? > > All explainations I have seen in books and blogs don't make it clear. > my @new = map {$_} @arr;

Map function, what does it do?

2011-01-11 Thread Sean Murphy
Hi all. I have read the explaination of the Map function and it is still a mystry to myself on what it is for and when would you use it? All explainations I have seen in books and blogs don't make it clear. Sean -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional comm