vi / perl question

der.hans plug-devel@lists.PLUG.phoenix.az.us
Sat Dec 1 15:48:01 2001


Am 28. Nov, 2001 schwätzte Carl Parrish so:

> I'm working with a CGI application. Its writting to a flat file db. The 
> flat file reades each line as a new record. Well in one of the fields 
> the user can type in a enter. Which of course screws with reading the 
> flat file. So I thought I'd just substutie the enters with another 
> delimiter. Piece of cake. Only I don't seem to be able to find the 
> enters. I thought doing a search for either "\n" or "\r" would do it but 
> so far no luck. (In vi here is the command :%s/\n/:::/g ). Is there 
> another escape char I should be looking for? Or should I try the hex code?

\n should work from *NIX boxen. Not sure about m$, but I think it still
works there.

lufthans@fs:~$ cat /tmp/carl.pl 
#!/usr/bin/perl

$fred ="anke
georg
uwe";
print "<$fred>\n";

@fred = split( '\n', $fred );
foreach $entry ( @fred ) {
        print "<$entry>\n";
}

$fred =~ s/\n/<here be newlines>/g;
print "<$fred>\n";
lufthans@fs:~$ /tmp/carl.pl 
<anke
georg
uwe>
<anke>
<georg>
<uwe>
<anke<here be newlines>georg<here be newlines>uwe>

Sorry, don't feel like doing cgi :). Potential probs when coming from cgi is
that you're getting something other than \n.

Don't forget to look for control chars as well.

ciao,

der.hans
-- 
#  http://home.pages.de/~lufthans/   http://www.DevelopOnline.com/
# Nobody grows old merely by living a number of years.
# We grow old by deserting our ideals.
# Years may wrinkle the skin, but to give up enthusiasm
# wrinkles the soul.  -- Samuel Ullman