jjohhn has asked for the wisdom of the Perl Monks concerning the following question:
I want:
('one',
'two',
'three')
this sed script seems to work:
sed -e s/\(.*\)/'\1',/g -e 1s/\(.*\)/(\1/ -e $s/\(.*\),/\1)/$s/\(.*\),/\1)/
but I was hoping perl could do it more readably or simply. The last line, where the comma should be missing, is hard to achieve. This is what I have so far:
but you can see that the last line isn't quite right. Any thoughts?use strict; my $line; while(<>){ chomp; s/^/'/g; s/$/',/g; if($.==1){ s/^/(/;} print $_,"\n"; $line=$_; # this is where I am stuck; I need to test if we are at the last line. }
|
|---|