Re: upper/lower case

"[email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
Can you please lay out the reasons you thought that my posting scores on the obscurity index. Could it be that there were no accompanying comments? Also , this post was not for speed reasons, rather to ameliorate the while-loop construct to be able to skip processing the first line of input.
 

---In [email protected], <dgoldman@...> wrote :

 You probably did make it as modular as bash/sed would allow. I applaud 
 it. However, if you're saying you don't think it's obscure, I would 
 definitely not agree with that.
 
 I have to tread a little lightly, because "obscurity" can descend into a 
 "religious war" unless one is careful. I should just say that I was 
 hard-pressed to tell what is going to happen by scanning the code, and I 
 am no newbie. Based on my experience, I think the great majority of 
 programmers would be hard pressed, but that is just my opinion. In 
 contrast, the cut-paste solution is pedestrian, but each step seems 
 clear and logical. It does require knowing cut-paste, but I think that 
 is pretty basic knowledge.
 
 Of course, part of obscurity relates to what we are used to. For a 
 non-programmer, everything is obscure. To someone who knows no regex, 
 just about any regex is obscure. etc. You're a brilliant programmer in 
 some ways, come up with clever solutions that I don't expect. But what 
 is obvious to you may be obscure to others. We might define "obscure" as 
 "hard for others to understand and maintain". The key word is "others". 
 For me, when I write something, I try to put myself in the shoes of 
 someone else, of average competency, looking at the code for the first 
 time, or in the shoes of myself looking at the code for the first time 
 in a year. By those criteria, I think the code is obscure.
 
 If you want to know specifics of why I think the code is obscure, I 
 could share that, but do not want to bog down the group. You could 
 contact me offline, or ask here if you prefer. I'm of two opinions. I 
 think code readability is very important, in almost all cases second in 
 importance only to correct operation, that much code is rather poorly 
 written, and that readability is a real thing that even can be measured. 
 OTOH, I am a little concerned about the partial "religious war" aspect 
 (X sucks!, Y rocks!, vi vs emacs, etc.), and that code readability is 
 such a huge subject that it might get a bit off topic.
 
 Daniel
 
 On 12/12/2015 12:11 PM, [sed-users] wrote:
 
 >> That is quite a feat you did! Of course, now it's very obscure, a huge negative, probably about as obscure as the perl solution. But at least you did it.
 >
 > When I posted the code, I tried to make it as modular as bash/sed would allow me to, thinking that it wouldn't be obscure. hmmm....
 >
 > > This will ensure that the first line is not modified...
 >
 >> #!/bin/sh -u
 >
 >> c=3; # column to sed
 >> d=\;; # csv delimiter character
 >
 >> code="
 >> ${c}{
 >> s/.*/\L&/;
 >> s/\<[a-z]/\u&/g;
 >> }
 >> H;1h;\$!d;
 >> g;y/\\n/$d/;
 > > "
 >
 >
 >
 > > flag=
 >> while IFS= read -r Line; do
 >> case $flag in '' ) printf '%s\n' "$Line"; flag=1; continue;; esac;
 >> set -f;
 >> IFS=$d; set X $Line; shift;
 >> printf '%s\n' "$@" | sed -e "$code";
 >> done < input.csv
 >
 >
 >
 > ---In [email protected] mailto:[email protected], <dgoldman@...> wrote :
 >
 > That is quite a feat you did! Of course, now it's very obscure, a huge
 > negative, probably about as obscure as the perl solution. But at least
 > you did it. The parameter-driven while-loop script would have to be
 > fixed up not to operate on the first line, but I'm sure that could be
 > done (I'm not suggesting you do it!). Anyway, as usual, there are
 > several ways to do something, with advantages and disadvantages.
 >
 > Daniel
 >
 > On 12/12/2015 11:00 AM, [sed-users] wrote:
 > > Of course the while-loop script can also be made parameter driven:
 > >
 > >
 > > #!/bin/sh -u
 > >
 > >
 > > c=3; # column to sed
 > > d=\;; # csv delimiter
 > >
 > >
 > > lc_code="$c!b;s/.*/\L&/;s/\<[a-z]/\u&/g"; # sed code to lowercase
 > > pr_code="H;1h;\$!d;g;y/\\n/$d/"; # sed code to print line
 > >
 > >
 > > while IFS= read -r Line; do
 > > set -f;
 > > IFS=$d; set X $Line; shift;
 > > set X $(printf '%s\n' "$@" | sed -e "$lc_code"); shift;
 > > echo "$@" | sed -e "$pr_code";
 > > done < input.txt
 > >
 > >
 > >
 > > HTH
 > >
 > >
 > > -Rakesh
 > >
 >
 >
 >
 > [Non-text portions of this message have been removed]
 >
 >
 >
 > ------------------------------------
 > Posted by: sharma__r@... mailto:sharma__r@...
 > ------------------------------------
 > 




[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.