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

I'm trying to pipe data from this url

http://parazen.bio.indiana.edu/me/monks.html
to this url
http://parazen.bio.indiana.edu/cgi-bin/monks.pl

I'm using GET to transfer the information. However, I can't seem to preserve the carriage returns. How do I do this?

The following is wrapped in |code| tags but it doesn't seem to shrink it. Also sorry about the anonymous post. I don't know why it did that.

getParamaters(); $data = $getParam{'hand_history'}; print "$data <br>"; sub getParamaters{ if ($ENV{'CONTENT_LENGTH'} > 0) { # read POST data from STDIN print "READING POST DATA\n"; read STDIN, $temp, $ENV{'CONTENT_LENGTH'}; # add in the GET data: $temp.="&".$ENV{'QUERY_STRING'} if length <br>$ENV{'QUERY_STRING +'}; } else { # read only the GET data #print "READING GET DATA\n<br>"; $temp=$ENV{'QUERY_STRING'}; } # separate each keyword foreach ( split( /&/, $temp ) ) { # separate the keys and values ( $key, $val ) = split( /=/, $_, 2 ); # translate + to spaces $key=~s/\+/ /g; $val=~s/\+/ /g; # translate %xx codes to characters $key=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie; $val=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie; $getParam{$key} = $val; }

Edited by Chady -- removed <br> tags from code.

Replies are listed 'Best First'.
Re: Line break problems
by nedals (Deacon) on Sep 03, 2005 at 02:00 UTC

    What 'carriage returns' are you trying to preserve.
    The code indicates that you are getting data from a 'post' or a 'get'.

    For that you should be using the CGI module instead of trying to roll your own. In addition you should be using 'strict'

    use strict; use CGI; my $q = new CGI; my $data = $q->param('hand_history');
Re: ugh... line breaks
by CountZero (Bishop) on Sep 02, 2005 at 23:19 UTC
    But it does preserve the line breaks, only line-breaks are the same as whitespace in HTML, so they have no special meaning. Just look at the source of the web-page and you will see the line breaks are still there.

    What you can do is replace all linebreaks by <br/> tags and you will get the effect you want. Or you could simply enclose the text in <pre>...</pre> tags or use a module like Formatter::HTML::Preformatted.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law