[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('>','>',re.sub('<','<',re.sub('&','&',text)))
... but to also avoid multiple statements like this:
my $tmp = $_;
$tmp =~ s/&/&/g;
$tmp =~ s/</</g;
$tmp =~ s/>/>/g;
return $tmp;
But maybe it'd be useful to have more visual weight than 's' carries:
return $_.s:e/&/&/.s:e/</</.s:e/>/>/; # line noise?
return $_.sub:e("&","&").sub:e("<","<").sub:e(">,>") # awkward
return $_.sub:e(&)(&).sub:e(<)(<).sub:e(>)(>) # hmmm
But I forget whether we're allowed space by the dot, which could help.
return $_ . s:e/&/&/ . s:e/</</ . s:e/>/>/; # 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