Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

foreach or map (perl 5)

Status
Not open for further replies.

northernbloke

Programmer
Aug 9, 2000
29
GB
I am a recent perler... I have perl 5 on my box. I am digging my way through perl and I have come across the map function.

@newlist = map(&mysub($_), @list);

is this better/worse than foreach - or are they the same thing ??
 
The map function is really a way of creating a NEW array (or list) from an existing array (or list) in a compact way. The same thing CAN be done with a foreach, but not as compactly or efficiently, since you have to create the new array yourself within the foreach loop. Remember one of the most important perl mottos: TMTOWTDI (There's More Than One Way To Do It). Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top