tcheungcm has asked for the wisdom of the Perl Monks concerning the following question:

hi I am having a problem to replace a special character ^@.
When I tried to read a file with a multiple lines, each line has a special ^@
20111107.............^@^@
1234ABCD12334........^@
1234ABCD96758........^@
I am trying to use the following way to remove this char but the line was unable to remove.
while(readline $filein) {
my $line = $_;
$line =~ s/^@+$//g;
}
When I print the line again, all the lines were screwed and print differently on ths second line. Can someone help? If you use vi editor, the specical char is created with Control-V Control-@ key strokes

Replies are listed 'Best First'.
Re: replace specical char ^@ to empty char
by ikegami (Patriarch) on Nov 07, 2011 at 04:30 UTC

    ^@ is often used to represent chr(0).

    Each of these will do:

    s/\0//g; s/\c@//g; s/\x00//g;
Re: replace specical char ^@ to empty char
by Anonymous Monk on Nov 07, 2011 at 12:15 UTC
    If the two-character string "^@" actually does appear in the file, rather than being a representation of a null, then you would need to escape each character in the pattern, and use a grouping to indicate that the pair of characters may repeat: s/(?:\^\@)+$//g