Hi,

Unable to remove the ^M character

Having one trigger that should rewrite the file content with copyright statements during check out.

Workout: File doesn't have ^M character prior to check out. It is working fine in solaris view and windows view. Since tried to check out the same file in imported view(the view which is imported from unix to windows), it was added with ^M at end of each line of file content.

Tried to remove the ^M once rewrite done for the copyright statement using tie function in many ways

But didn't get the expected result

File prior to check out:

class Test { public static void main(String[] args) { System.out.println("Hello Test!"); } }

File once check out done in unix view:

vi test.java //**************************************************** // Copyright (c) 2009, Inc. // All rights reserved. //**************************************************** class Test { public static void main(String[] args) { System.out.println("Hello Test!"); } }

File once check out done in imported view(unix style view) in windows:

L:\test>ct co -nc test.java vi test.java //****************************************************^M // Copyright (c) 2009 Systems, Inc. ^M // All rights reserved. ^M //****************************************************^M ^M class Test ^M {^M public static void main(String[] args) ^M {^M System.out.println("Hello Test!");^M }^M }^M

Tried in following ways to remove the ^M and was not able to remove the ^M

my @lines; if($imported_view){ print "\nInside IF loop\n"; tie( @lines, 'Tie::File', "$File" ) || die("can't open $File: +$!"); my $size = @lines; my $i; for ( $i = 0 ; $i < $size ; ++$i ) { print "Current Line:$lines[$i]\n"; #$lines[$i] =~ tr/\r\n//d; #$lines[$i] =~ s/\x0D$//g; #$lines[$i] =~ s/0d$//g; #$lines[$i] =~ s/\r\n$//g; #$lines[$i] =~ tr/\cVM//d; #$lines[$i] =~ tr/^$//d; } untie @lines; }

Thanks in advance,

Kavitha


In reply to Unable to remove the ^M character by kkavitha

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.