[EMAIL PROTECTED] wrote:
> Smylers wrote:
>> This, however, is irritating:
>>
>>   my @new = map { s:e/$pattern/$replacement/; $_ } @old;
>>
>> So I'd like a more elegant way of writing that -- but I don't think
>> making the return value of C<s///> more complicated (and duplicating
>> data in the process) would be a nett gain.

I'd agree - appearing to have the functional behaviour, but actually
trashing the original string as well, sounds like a great way to confuse
people.

> What if the method form of s/// didn't mutate the string, but returned
> the mutated result?  Then, you'd just need to do something like:
>
>   my @new = map { $_.s:e/$pat/$rep/ } @old
>
> Except I don't know how the method form of s/// would be spelt.
> 
>   $string.s:e/$pat/$rep/;     # . and ~~ are almost the same?
>   $string.sub($pat,$rep,"each");  # ick.
>   $string.sub:e($pat,$rep);   # hmm.

Hmmm.  When doing multiple substitutions, it would be nice to avoid a
hard-to-read nested function call which reads backwards, a la python:

  return re.sub('>','&gt;',re.sub('<','&lt;',re.sub('&','&amp;',text)))

... but to also avoid multiple statements like this:

  my $tmp = $_;
  $tmp =~ s/&/&amp;/g;
  $tmp =~ s/</&lt;/g;
  $tmp =~ s/>/&gt;/g;
  return $tmp;

But maybe it'd be useful to have more visual weight than 's' carries:

  return $_.s:e/&/&amp;/.s:e/</&lt;/.s:e/>/&gt;/;   # line noise?
  return $_.sub:e("&","&amp;").sub:e("<","&lt;").sub:e(">,&gt;") # awkward
  return $_.sub:e(&)(&amp;).sub:e(<)(&lt;).sub:e(>)(&gt;) # hmmm

But I forget whether we're allowed space by the dot, which could help.

  return $_ . s:e/&/&amp;/ . s:e/</&lt;/ . s:e/>/&gt;/;   # readabler

-- 
$_=".--- ..- ... -  .- -. --- - .... . .-.  .--. . .-. .-..  .... .- -.-.".
" -.- . .-.\n";s!([.-]+) ?!$_=$1;y/-./10/;$_=chr(-1+ord pack"B*","01".0 x(5
-length)."1$_");y/DWYKAQMOCVLSFENU\\IGBHPJXZ[~nfb`_ow{}/a-z0-9/;$_!ge;print

Reply via email to