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

In reply to Re: Convert from Sed to Perl by oko1
in thread Convert from Sed to Perl by mc007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.