[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Question - Substitution



At 19.08 -0500 1998.12.23, Gene Hsu wrote:
>>But to actually provide a solution, I'd suggest you use map...
>>
>>	map {s/\s$theName\s/ <a href="c$j.html">$theName<\/a> /g} @theInfo;
>
>Then again, you might want to use a for loop:
>
>for (@theInfo) { [put your substitution here] }
>
>AFAIK, the difference between map and for in this case is that map creates
>a temporary array for the return value, and for has no return value.  I
>remember there being some religious discussion in the newsgroup about this
>issue (when to use for vs. map).

Yes, map in a void context is wasteful.  I don't know if that has been
fixed in 5.005.  But in 5.005, you can also do:

  s/match/replace/g foreach @array;

Kinda cool.  :)

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch