[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacement strings
From: |
Ole Tange |
Subject: |
Re: Replacement strings |
Date: |
Fri, 4 Jul 2014 22:31:14 +0200 |
On Wed, Jul 2, 2014 at 2:16 PM, Achim Gratz <Stromeko@nexgo.de> wrote:
> Ole Tange <ole <at> tange.dk> writes:
>> I was wrong. I analysed a few million lines of perl code: {{...}} is
>> not that uncommon. However, {= ... =} is extremely uncommon. So unless
>> there are heavy reason not to, then {= ... =} will be the magic
>> braces.
>
> This is also fantastically complicated to type, depending on the keyboard
> language and how you get at the alternate characters. If you are insisting
> on the braces, then please consider at least using {~ ... ~}.
I am open to other ideas. To type: {= I use 4 key presses on my Danish
keyboard. To type {~ I use 5. So from a pure key press aspect ~ is
worse than = for Danish keyboards.
I was worried that bash would expand the ~ but bash seems not to do
that, so it might work, too.
To me it is more important that it looks nice/is readable than whether
it is hard to type.
parallel --rpl '{+} {= $_+=10 =}' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} {= s/(\.[^.]+){2}$// =}' echo {..} :::
dir/file.ext1.ext2
foo{= s/(\.[^.]+){2}$// =}bar
parallel --rpl '{+} {~ $_+=10 ~}' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} {~ s/(\.[^.]+){2}$// ~}' echo {..} :::
dir/file.ext1.ext2
foo{~ s/(\.[^.]+){2}$// ~}bar
parallel --rpl '{+} {. $_+=10 .}' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} {. s/(\.[^.]+){2}$// .}' echo {..} :::
dir/file.ext1.ext2
foo{. s/(\.[^.]+){2}$// .}bar
parallel --rpl '{+} {_ $_+=10 _}' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} {_ s/(\.[^.]+){2}$// _}' echo {..} :::
dir/file.ext1.ext2
foo{_ s/(\.[^.]+){2}$// _}bar
parallel --rpl '{+} {: $_+=10 :}' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} {: s/(\.[^.]+){2}$// :}' echo {..} :::
dir/file.ext1.ext2
foo{: s/(\.[^.]+){2}$// :}bar
parallel --rpl '{+} {, $_+=10 ,}' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} {, s/(\.[^.]+){2}$// ,}' echo {..} :::
dir/file.ext1.ext2
foo{, s/(\.[^.]+){2}$// ,}bar
I am not sure which I like better. They all look like noise on a modem line ;-)
I am open to other digraphs. I will prefer that they are not
interpreted by the shell and that their frequency in perl code is
minimal.
I have analyzed 2 GB of perl code. Here are the frequencies:
http://ole.tange.dk/perl-code-bigram-freq.bz2
So far I have focused on using a mirrored bigram, because that
resembles the {} construct used so far. But other bigrams may work,
too. An option could be: ^^ (frequency 9900 compared to 5162 for '{=
=}'). ^^ has the benefit of not being interpreted by neither bash nor
tcsh:
parallel --rpl '{+} ^^ $_+=10 ^^' -n2 echo {1+} {2+} ::: 10 20
parallel --rpl '{..} ^^ s/(\.[^.]+){2}$// ^^' echo {..} :::
dir/file.ext1.ext2
foo^^ s/(\.[^.]+){2}$// ^^bar
Feel free to look at the frequencies and see if you can find something
you prefer.
> How about
> using digraphs or trigraphs instead? The ??( ... ??) sequence works well
> for me
That, however, is no-go: Bash complains about the ( if not quoted.
I will prefer not going into tri-graphs: It will take up too much space.
> but admittedly it is somewhat less easily reachable with a US ASCII
> keyboard layout. The digraph %< .. %> on the other hand doesn't work well
> on a german keyboard while it is quite nice on US ASCII.
< and > are also no-go: Bash will interpret those.
/Ole