Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

problem with extra lines when using

by belize (Deacon)
on Aug 14, 2001 at 19:18 UTC ( #104793=perlquestion: print w/replies, xml ) Need Help??

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

I have a form that is using the POST method to add to a flat file database.

The parse subroutine uses the following lines:

$name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
I am having trouble because the output has far too many "returns" placed in it.

I am previewing the output prior to adding to the database by placing the values into another form. But, the "returns" (\n) are continually multiplied with each preview/modify so that what is finally printed into the flatfile has far to much space between what should only be paragraphs.

I placed print statements before and after the above lines and here is the output:




Nautical Inn Resort, located on Placencia Peninsula, Belize, offers be +ach accommodations, great dining, SCUBA diving, snorkeling, Jaguar Re +serve, Monkey River, Maya Ruins plus the culture of Garifuna drummers + and dancers all rolled into an exciting Belize vacation. You'll find + us where the Caribbean meets the jungle! Nautical Inn occupies 4 acres on Placencia Peninsula. Twelve beach fro +nt rooms have air conditioning, ceiling fans, modern bathrooms and gr +eat beds. Mahogany and wicker furniture are accented with a nautical +theme. The Oar House is the place for fine dining and Caribbean cockt +ails. The daily activity board lists tours and excursions to help you + see Belize from the reef to the rainforest.

Now, when I submit the preview form, the space between paragraphs is doubled. And if I use a modify form, the space is again doubled.

Can you explain what is going on?

Replies are listed 'Best First'.
Re: problem with extra lines when using
by chipmunk (Parson) on Aug 14, 2001 at 19:55 UTC
    I suspect that you have "\r\n" line-endings, and somewhere along the way the \r is turning into an extra newline.

    So, just s/\r\n/\n/g; before doing anything with the data, and you should be okay.

Re: problem with extra lines when using
by ralphie (Friar) on Aug 14, 2001 at 22:47 UTC
    how are you writing the lines? i had a similar problem with database inserts that turned out to be a problem with appropriately quoting the scalars that were determined as part of an outer loop ... each time the inner loop was executed more inappropriate characters were placed in the scalar.
Re: problem with extra lines when using
by tachyon (Chancellor) on Aug 15, 2001 at 03:24 UTC

    While chipmunk will no doubt be right about the extra \r you are obviously hand parsing the CGI data which is part of the problem. Could I suggest you check out use CGI or die; and no excuses about not using as well as Ovid's most excellent CGI tutorial.




Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://104793]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-10-24 19:23 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.