map takes a code block or an expression and evaluates it for each element in a list
for example... my @arr = (1,2,3,4,5); my @arr2 = map {$_ + 3} @arr; # notice no comma print "@arr2\n"; 4 5 6 7 8 So, each element of @arr had 3 added to it. Another example, using an expression would be my @arr2 = map(chr, (65, 66, 67)); print "@arr2\n"; A B C This took the expression (chr) and mapped it over the list (65, 66, 67) which caused each number to be changed to its character equivalent. If you have a general expression my @arr2 = map BLOCK LIST you can think of it as being foreach (LIST) { BLOCK; push( $_, @arr2 ); } So, the purpose of map is to change every element of an array in the same way and create a new array with those changed elements. You may also wish to look at map's cousin grep, which works in a similar fashion, but is used to find elements in an array that match a certain criteria. perldoc -f map perldoc -f grep Tanton ----- Original Message ----- From: "Mystik Gotan" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, November 24, 2002 8:27 AM Subject: I need some explainment on the MAP() Function > My last question... It's getting a bit too much.. I'm sorry for asking so > much.. But I find it quite hard to understand the map() function. Can > anybody explain this? > > Again, apologise for asking so much. But I'm just a 14 year old Dutch boy so > sometimes it's a bit hard to follow the English references telling all about > OO Programming and stuff. I'm getting on quite good with Perl. I think > that's nice, cause I haven't seen any 14 year old Perl programmers. I'm not > saying I am, I did however wrote some scripts which come in handy quite > nicely. > > Any good explainment on the MAP function is really appreciated, since I only > really get 50% of the picture (it evaluates two variables with eatchother, I > suppose?). > > > > Sincerly, > Bob Erinkveld > (Webmaster Insane Hosts) > www.insane-hosts.net > > > > > _________________________________________________________________ > Direct chatten met je vrienden met MSN Messenger http://messenger.msn.nl > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]