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

Summary I am having a difficult time substituting the vertical tab "\v" with a newline "\n." For some reason, this does not work. The file is an outbound 820 (4010) EDI file. I cannot get the RegExp to work.
if (open(SF,"<$input")) { if (open(DF,">>$output")) { $fmt_edi = <SF>; $fmt_edi =~s/\v/\n/gs; print DF "$fmt_edi"; } else { } } else { } close DF; close SF;
Thanks in advance for any and all help.
vs

Replies are listed 'Best First'.
Re: Difficulty Substituting Vertical Tab With Newline
by jasonk (Parson) on Feb 24, 2003 at 22:15 UTC

    You have a couple of different problems here, the first is that you are reading SF into a scalar, $fmt_edi, when you evaluate a filehandle as a scalar, you only get one line at a time, so you will only get the first line of your input file processed. Second, the perlre documentation has a list of characters that are special when preceded by a backslash. The letter v is not in this list, which means that '\v' has the same meaning as 'v' and will replace all the lowercase letter v's with newlines. (perlre also indicates the 'vertical tabulator' character is \ck)

Re: Difficulty Substituting Vertical Tab With Newline
by blakem (Monsignor) on Feb 24, 2003 at 22:24 UTC
    Vertical tab is octal char 013 in ASCII, so if you have correctly slurped your data into $fmt_edi (which I don't think you have) the following should work.
    $fmt_edi =~ s/\013/\n/g;

    -Blake