in reply to Convert from Sed to Perl
Your subject is a bit misleading; you're not converting from 'sed' to Perl - you're converting from a KSH script (which happens to use 'sed') to Perl. As much as I like Perl, and use it for almost every task, for a short script that mostly uses file operations, I'd stick with the standard Unix utils - although I'd do it somewhat differently.
For one thing, since you're only writing your specified string into 'testfile2' - i.e., 'testfile' isn't actually being used in any way - then why not do exactly that? This example copies the action of your script:
#!/usr/bin/ksh echo 'test ' > testfile2 # echo $(/usr/bin/tput smso)broken$(/usr/bin/tput rmso) > testfile2
However, since this is a Perl forum:
#!/usr/bin/perl -w use strict; open F1, "testfile" or die "testfile: $!\n"; open F2, ">testfile2" or die "testfile2: $!\n"; while (<F1>){ s/.*/test /; # s/.*/`tput smso`.'broken'.`tput rmso`/e; print F2; last; } close F1; close F2;
-- Human history becomes more and more a race between education and catastrophe. -- HG Wells
|
|---|